-
-
Notifications
You must be signed in to change notification settings - Fork 545
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
Improve performance of convert_argument
for list of primitives
#3773
base: main
Are you sure you want to change the base?
Improve performance of convert_argument
for list of primitives
#3773
Conversation
…lars, optional scalars, enums)
Reviewer's Guide by SourceryThis pull request improves the performance of the convert_argument function for lists of primitive types by adding an early return mechanism and avoiding unnecessary element-by-element processing. The changes include a new helper function to determine if conversion can be bypassed, adjustments in the convert_argument logic for list types, and additional performance benchmarks. No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
for more information, see https://pre-commit.ci
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 @blothmann - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a comment to
_convert_argument_value_can_be_returned
explaining why LazyType and enums need to be resolved. - It might be worth adding a comment explaining why we can return the original value for scalars and enums.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
strawberry/types/arguments.py
Outdated
@@ -135,6 +135,31 @@ def is_graphql_generic(self) -> bool: | |||
return is_graphql_generic(self.type) | |||
|
|||
|
|||
def _convert_argument_value_can_be_returned( |
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.
can we find a different name for this? :D I don't think it is easy to understand (maybe we can add a doc string too)?
Great stuff btw 😊
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.
We are looking for a scalar or enum or an optional version of those, which can simply be returned in convert_argument. So maybe something like _is_primitive
?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3773 +/- ##
==========================================
- Coverage 97.24% 97.23% -0.02%
==========================================
Files 504 503 -1
Lines 33480 33487 +7
Branches 5502 1707 -3795
==========================================
+ Hits 32558 32561 +3
- Misses 703 708 +5
+ Partials 219 218 -1 |
CodSpeed Performance ReportMerging #3773 will not alter performanceComparing Summary
Benchmarks breakdown
|
Tried to make the function naming more clear to determine in which case a copy of the list can be returned: if item type is a leaf ( |
Improve performance of
convert_argument
for list types that do not need any conversion of its arguments by just returning a copy of the list.Description
This has a drastical improvement of the performance if the input list is large. In my use case under some circumstances I am handling lists of hundred thousands of elements. Instead of iterating through each element, checking some conditions and returning the element, just return a copy of the list is a huge performance improvement.
Since tests cover everything that I have changed already, I added a performance test for large lists of integers.
Types of Changes
Issues Fixed or Closed by This PR
Checklist
Summary by Sourcery
Optimize argument conversion for lists of primitive types by directly returning a copy of the list if no type conversion is required.
Enhancements:
convert_argument
for large lists of primitive types.Tests: