Skip to content

The latest version is slower than 3.2.0 validator #1231

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

Closed
samjuis opened this issue Mar 5, 2024 · 5 comments
Closed

The latest version is slower than 3.2.0 validator #1231

samjuis opened this issue Mar 5, 2024 · 5 comments
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup

Comments

@samjuis
Copy link

samjuis commented Mar 5, 2024

I would like to ask if I can replace 'for error in self.evolve(schema=schema).iter_errors(instance, schema)' in version 4.3.1: This line is 'for error in self.iter_errors(instance, schema)' in version 3.2.0 :, I found that this can reduce 2-3 seconds when traversing 500 times;

4.3.1
 for error in self.evolve(schema=schema).iter_errors(instance):

12 sec

3.2.0
for error in self.iter_errors(instance, schema):

After use  9sec

In addition, my current version is 4.0.1, just replace the 'find_item' in the 'resolve_fragment' method with find.

4.0.1
         for keyword in ["$anchor", "$dynamicAnchor"]:
            for subschema in self._finditem(document, keyword):
                 if fragment == subschema[keyword]:
                     return subschema
         for keyword in ["id", "$id"]:
             for subschema in self._finditem(document, keyword):
                 if "#" + fragment == subschema[keyword]:
                    return subschema

4.3.1
@lru_cache
def _find_in_referrer
.
.
.
        if document is self.referrer:
            find = self._find_in_referrer
        else:

            def find(key):
                return self._finditem(document, key)

        for keyword in ["$anchor", "$dynamicAnchor"]:
            for subschema in find(keyword):
                if fragment == subschema[keyword]:
                    return subschema
        for keyword in ["id", "$id"]:
            for subschema in find(keyword):
                if "#" + fragment == subschema[keyword]:
                    return subschema


@samjuis samjuis closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
@samjuis samjuis reopened this Mar 5, 2024
@samjuis
Copy link
Author

samjuis commented Mar 5, 2024

I understand part of the code. The reason why it is slower than the old version is that the verification items are constantly increasing. I am currently using Draft202012Validator. After switching to Draft4Validator, the difference is doubled (the original difference was five times). dont know if it is like this

@Julian
Copy link
Member

Julian commented Mar 5, 2024

I don't know what you're meaning to report with this issue. 4.3.1 is a very old version, and 3.2.0 is an ancient one.

If you're trying to report any issue, you need to include a minimal working example of what you ran and what the change was.

@Julian Julian closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
@samjuis
Copy link
Author

samjuis commented Mar 5, 2024

for the old version (4.0.1) I just want to speed up the execution to be close to version 3.2.0 (or older), because the latest version is slower than version 4.3.1 (as per issue #853 first (the result of running a test case)), I gave up this version and came here to ask for advice.

@Julian
Copy link
Member

Julian commented Mar 5, 2024

Slower on what? #853 is a very old issue about a very old version. The current version of this library is 4.21.1, which is the only version I support.

@samjuis
Copy link
Author

samjuis commented Mar 5, 2024

Ok, I see. Thanks. I've found the solution. The new version does not have this problem, and the efficiency has returned to that of the ancient version.

@Julian Julian added the Invalid Not a bug, PEBKAC, or an unsupported setup label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup
Projects
None yet
Development

No branches or pull requests

2 participants