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

feat(django_getter): use function cache to increase performance #1150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yorickr
Copy link

@yorickr yorickr commented May 3, 2024

Hi!

After using ninja a lot, I noticed some performance benefit could be made in DjangoGetter, by caching the actual function being called and using a lookup, instead of doing up to 4 checks each time.

This MR implements this simple cache.
I didn't specifically add tests for this, as schema is tested very well throughout the rest of the tests. Let me know if you'd like to see this differently.

Let me know what you think!

Some data:

Old code: Average time across 20 runs of 100k nested objects is 5.516484143049911
New code: Average time across 20 runs of 100k nested objects is 4.045871758400063
This is 1.5s saved, or 27% saved.

Old code: Average time across 20 runs of 10k nested objects is 0.4554609017498933
New code: Average time across 20 runs of 10k nested objects is 0.35757346044997573
This saved 22%.

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.

None yet

1 participant