Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve canonicalisation for conditional keywords #73

Conversation

Stranger6667
Copy link
Contributor

I noticed that some conditional schemas are canonicalised very slow, consider this one:

SCHEMA = {
    "if": {
        "if": {"if": {"type": "null"}, "then": {"type": "null"}},
        "then": {"if": {"type": "null"}, "then": {"type": "null"}},
    },
    "then": {
        "if": {"if": {"type": "null"}, "then": {"type": "null"}},
        "then": {"if": {"type": "null"}, "then": {"type": "null"}},
    },
}

On my machine, each canonicalish call takes ~ 30ms, but if the "if" schema is equal to "then" and there is no "else" (or it is truthy), then this condition is a no-op.

It is slightly related to #64, where the example was not canonicalised to {"not": {}}, with this change it does, but it doesn't solve the general case with anyOf, though (as per your comment)

@Stranger6667 Stranger6667 changed the title Improve performance for conditional keywords Improve canonicalisation for conditional keywords Nov 21, 2020
@Stranger6667 Stranger6667 force-pushed the dd/improve-conditionals branch from efa4668 to 65d7af1 Compare November 21, 2020 10:49
@Zac-HD
Copy link
Member

Zac-HD commented Nov 22, 2020

Merged via f40063a - apparently github doesn't pick up on that since I rebased the conflict away 🤷‍♂️

As usual, thanks for the patch!

@Zac-HD Zac-HD closed this Nov 22, 2020
@Stranger6667 Stranger6667 deleted the dd/improve-conditionals branch November 22, 2020 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants