Skip to content

The latest version is slower than 3.2.0 validator #1231

Closed as not planned
Closed as not planned
@samjuis

Description

@samjuis

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


Metadata

Metadata

Assignees

No one assigned

    Labels

    InvalidNot a bug, PEBKAC, or an unsupported setup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions