Skip to content

get_validator takes too much time #289

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
sjiekak opened this issue Feb 12, 2021 · 3 comments · Fixed by #292
Closed

get_validator takes too much time #289

sjiekak opened this issue Feb 12, 2021 · 3 comments · Fixed by #292
Labels
area/unmarshalling Indicates an issue on unmarshalling area.

Comments

@sjiekak
Copy link

sjiekak commented Feb 12, 2021

I benchmarked a validation against a json input of roughly 700k characters, and it seems deepcopy of the checker is the costliest operation

snakeviz performance validate

get_validator relies on _get_format_checker

    def _get_format_checker(self):
        fc = deepcopy(oas30_format_checker)
        for name, formatter in self.custom_formatters.items():
            fc.checks(name)(formatter.validate)
        return fc

The deepcopy of oas30_format_checker is where most of the time is spent. Can you help me understand why there is a need for deepcopy ?

@p1c2u
Copy link
Collaborator

p1c2u commented Feb 12, 2021

Hi @sjiekak
That's interesting. I wasn't aware of deepcopy slowness . This part of code is responsible for creation of format checker and I use oas30_format_checker for default formats and add custom ones with checks method. You need to get new object not the reference for that otherwise you will end up having custom formats inside default oas30_format_checker .
This can be problematic when you have more specs with different custom formats or when you use oas30_format_checker somewhere else.
I'm wondering if shallowed copy would be better here.

@p1c2u p1c2u added the area/unmarshalling Indicates an issue on unmarshalling area. label Feb 12, 2021
@p1c2u
Copy link
Collaborator

p1c2u commented Feb 13, 2021

One more thing is you have high number of calls for copy which can be because of many requests.
Solution for that can be keeping reference to custom format checker and reusing it for each request.

@sjiekak
Copy link
Author

sjiekak commented Feb 15, 2021

Thanks for the swift reaction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/unmarshalling Indicates an issue on unmarshalling area.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants