-
-
Notifications
You must be signed in to change notification settings - Fork 577
⚡️ Speed up function process_result
by 12% in PR #3819 (feature/defer
)
#3938
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
Conversation
We need to un-hardcode the label
…efer`) (#3827) Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
…fer`) Here is an optimized version. Improvements. - Removed the unnecessary intermediate variables (`errors`, `extensions`) that are only used once. - Avoided repeated dictionary unpacking by building the dictionary with direct assignments and only adding keys if necessary. - Used `if-else` statements for error and extensions blocks for slight speed-ups over dictionary unpacking on small dicts. Rewritten code. This version allocates less intermediate data and does not do work unless necessary.
Reviewer's GuideThis PR optimizes the process_result function by removing unneeded intermediates and replacing repeated dictionary unpacking with targeted conditional assignments, reducing allocations and improving runtime by about 12%. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
PR Summary
Optimized the process_result
function in strawberry/http/__init__.py
for a 12% performance improvement by streamlining dictionary construction and variable handling.
- Eliminated intermediate variables for
errors
andextensions
, reducing memory allocations - Replaced dictionary unpacking with direct key assignments for better performance
- Added comprehensive test suite with 40 test cases covering edge cases and large-scale inputs
- Improved handling of conditional additions to response dictionary
- Maintains identical functionality while reducing execution time from 100μs to 89.8μs
1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile
|
⚡️ This pull request contains optimizations for PR #3819
If you approve this dependent PR, these changes will be merged into the original PR branch
feature/defer
.📄 12% (0.12x) speedup for
process_result
instrawberry/http/__init__.py
⏱️ Runtime :
100 microseconds
→89.8 microseconds
(best of153
runs)📝 Explanation and details
Here is an optimized version. Improvements.
errors
,extensions
) that are only used once.if-else
statements for error and extensions blocks for slight speed-ups over dictionary unpacking on small dicts.Rewritten code.
This version allocates less intermediate data and does not do work unless necessary.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr3819-2025-07-01T11.11.27
and push.Summary by Sourcery
Optimize process_result performance by refactoring response object construction to reduce unnecessary intermediate data allocations and conditionalize the inclusion of errors and extensions.
Enhancements:
Tests: