Skip to content

Cache node hashing #150

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

Merged
merged 2 commits into from
Dec 11, 2021
Merged

Cache node hashing #150

merged 2 commits into from
Dec 11, 2021

Conversation

AlecRosenbaum
Copy link
Contributor

This change adds basic caching for Node.__hash__. The primary goal of this change is to optimize validation. The benchmark I tested against is tests/benchmarks/test_validation_gql.py.

Locally, this benchmark goes from 7ms to 4ms with this change. I've also done some testing against an internal schema from our application, using a large query from our application instead of the introspection query. In that test, validation time dropped from 28ms to 11ms locally.

@AlecRosenbaum AlecRosenbaum requested a review from Cito as a code owner December 10, 2021 15:31
@Cito
Copy link
Member

Cito commented Dec 10, 2021

Thanks, will check this out. One minor disadvantage ist that when you modify the AST, then you must also reset the cashed hash value. Or maybe we should do it automatically in the __setattr__ method?

@Cito Cito self-assigned this Dec 10, 2021
@Cito Cito added this to the v3.2 milestone Dec 10, 2021
@Cito Cito added the optimization Code optimizations and performance issues label Dec 10, 2021
@AlecRosenbaum
Copy link
Contributor Author

Good idea. I get about the same results with an added __setattr__ override that resets _hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Code optimizations and performance issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants