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

Defer creation of SimpleCookie objects in the web server until needed #9895

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

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Nov 15, 2024

related issue #2779

We create these objects even if there are no cookies. There are some small performance improvements and some memory savings on each request.

@bdraco bdraco added the backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot label Nov 15, 2024
Copy link

codspeed-hq bot commented Nov 15, 2024

CodSpeed Performance Report

Merging #9895 will improve performances by 17.52%

Comparing web_cookies_lazy (8ae15f7) with master (9ca1a58)

Summary

⚡ 4 improvements
✅ 38 untouched benchmarks

Benchmarks breakdown

Benchmark master web_cookies_lazy Change
test_simple_web_response 813.7 µs 727.5 µs +11.84%
test_simple_web_stream_response 560.8 µs 477.2 µs +17.52%
test_web_response_with_bytes_body 907.6 µs 818.5 µs +10.88%
test_web_response_with_text_body 1,037.8 µs 953.4 µs +8.86%

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.72%. Comparing base (9ca1a58) to head (8ae15f7).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9895      +/-   ##
==========================================
+ Coverage   98.70%   98.72%   +0.02%     
==========================================
  Files         121      121              
  Lines       36621    36629       +8     
  Branches     4376     4378       +2     
==========================================
+ Hits        36146    36163      +17     
+ Misses        319      314       -5     
+ Partials      156      152       -4     
Flag Coverage Δ
CI-GHA 98.61% <100.00%> (+0.01%) ⬆️
OS-Linux 98.30% <100.00%> (+0.01%) ⬆️
OS-Windows 96.12% <100.00%> (+0.08%) ⬆️
OS-macOS 97.39% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.24% <100.00%> (+<0.01%) ⬆️
Py-3.10.15 97.84% <100.00%> (+0.05%) ⬆️
Py-3.11.10 97.83% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.29% <100.00%> (+<0.01%) ⬆️
Py-3.12.7 98.32% <100.00%> (-0.04%) ⬇️
Py-3.13.0 98.35% <100.00%> (-0.01%) ⬇️
Py-3.9.13 97.17% <100.00%> (+0.30%) ⬆️
Py-3.9.20 97.71% <100.00%> (+0.70%) ⬆️
Py-pypy7.3.16 97.32% <100.00%> (?)
VM-macos 97.39% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.30% <100.00%> (+0.01%) ⬆️
VM-windows 96.12% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco
Copy link
Member Author

bdraco commented Nov 16, 2024

Todo

  • Focused benchmarks for creating web Responses and StreamResponses as we only have visibility on the more macro benchmark here
  • Add test coverage for overriding an already set cookie

related issue #2779

We create these objects even if there are no cookies
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Nov 17, 2024
Comment on lines -949 to -951
if old is not None and old.coded_value == "":
# deleted cookie
self._cookies.pop(name, None)
Copy link
Member Author

Choose a reason for hiding this comment

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

This was unreachable since cookies are always set with a path

@bdraco bdraco changed the title DNM: Defer creation of SimpleCookie objects in the web server until needed Defer creation of SimpleCookie objects in the web server until needed Nov 17, 2024
@bdraco bdraco marked this pull request as ready for review November 17, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant