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

perf(dependencies): skip doing any work when sub dependant is already cached #11323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xkabylgSICKAG
Copy link

@xkabylgSICKAG xkabylgSICKAG commented Mar 20, 2024

Hi, we noticed very large performance gains after making this change for our app that heavily uses the dependency injection system. One of our slower endpoints went from taking ~1100ms to ~400ms.

Copy link

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks really reasonable to check whether the sub_dependency is already solved and cached before solving it!

Related PR, that uses almost the same approach: #4089

Comment on lines 554 to 558
if (
sub_dependant.use_cache
and sub_dependant.cache_key in dependency_cache
and sub_dependant.name is not None
):
values[sub_dependant.name] = dependency_cache[sub_dependant.cache_key]
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (
sub_dependant.use_cache
and sub_dependant.cache_key in dependency_cache
and sub_dependant.name is not None
):
values[sub_dependant.name] = dependency_cache[sub_dependant.cache_key]
continue
if (
sub_dependant.use_cache
and sub_dependant.cache_key in dependency_cache
):
if sub_dependant.name is not None:
values[sub_dependant.name] = dependency_cache[sub_dependant.cache_key]
continue

To skip solving dependencies without name, that were already cached.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense 👍

In which cases will a sub_dependant not have a name?

@xkabylgSICKAG
Copy link
Author

@YuriiMotov

Related PR, that uses almost the same approach: #4089

That PR also has a test! :)

I think that other PR, with your suggested changes, is a better change than this PR. Do you think it makes more sense to close this in favour of the other one?

@xkabylgSICKAG
Copy link
Author

I've rebased and updated the PR with the suggested changes from @YuriiMotov and with the change to dependency_cache empty dict checking from #4089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants