-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Add caching for resolve
#3549
Add caching for resolve
#3549
Conversation
Reviewer's Guide by SourceryThis pull request addresses issue #3544 by replacing the File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @patrick91 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3549 +/- ##
=======================================
Coverage 96.57% 96.57%
=======================================
Files 524 524
Lines 33629 33630 +1
Branches 5578 5578
=======================================
+ Hits 32478 32479 +1
Misses 915 915
Partials 236 236 |
CodSpeed Performance ReportMerging #3549 will improve performances by ×7Comparing Summary
Benchmarks breakdown
|
reminder to make a pre-release and test on strawberry django & sqlalchemy (thanks @skilkis) |
@erikwrede yeah, but I'd like to check if we are doing too much useless work first :D |
75db9ca
to
1c3ccf9
Compare
Let's see what happens if I remove the cache
74cffa4
to
fff5021
Compare
b806091
to
a2cb19b
Compare
@@ -101,19 +101,17 @@ def annotation(self) -> Union[object, str]: | |||
def annotation(self, value: Union[object, str]) -> None: | |||
self.raw_annotation = value | |||
|
|||
self.__resolved_cached__ = None | |||
|
|||
def evaluate(self) -> type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is used in a couple of places directly, so we might want to reintroduce the cache, but I need to double check why we use it directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only use it here:
evaled_annotation = annotation.evaluate() |
@skilkis do you think it is worth caching the result here too? 😊
/pre-release |
Pre-release👋 Releasing commit [5224421] to PyPi as pre-release! 📦 |
Pre-release👋 Pre-release 0.235.1.dev.1719337273 [5224421] has been released on PyPi! 🚀 poetry add strawberry-graphql==0.235.1.dev.1719337273 |
just tested this on Strawberry Django and all the tests passed 😊 |
Thanks for adding the Here's a preview of the changelog: This release improves the performance when returning a lot of data, especially Here's the tweet text:
|
`resolve` is called every time we get the field type, which, turns out, is called a lot of times, even when creating the dataclass, maybe there's some opportunity for improvements here, but we would need to call `resolve` anyway, so it's probably not worth changing how this works
strawberry/annotation.py
Outdated
return self.__resolve_cache__ | ||
|
||
def _resolve(self) -> Union[StrawberryType, type]: | ||
# TODO: I wonder if this resolve should be creating types? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this here for the future 😊
`resolve` is called every time we get the field type, which, turns out,
is called a lot of times, even when creating the dataclass, maybe
there's some opportunity for improvements here, but we would need
to call `resolve` anyway, so it's probably not worth changing how this
works
Closes #3544
This PR adds cache to the
resolve
method to make sure we don't do the same work multiple times.