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

Improve performance of building the origin #1175

Merged
merged 3 commits into from
Oct 5, 2024
Merged

Improve performance of building the origin #1175

merged 3 commits into from
Oct 5, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Oct 5, 2024

What do these changes do?

  • Avoid rebuilding the netloc if there is no auth
  • Speed up building the netloc for the common cases ~9% measured on the aiohttp client benchmark
  • Cache the origin so we only build it once as aiohttp will call .origin() often on the same URL object when auth is enabled

Are there changes in behavior for the user?

no

Related issue number

fixes #1174

bdraco added 2 commits October 5, 2024 09:34
- Avoid rebuilding the netloc if there is no auth
- Cache the origin so we only build it once as
  aiohttp will call `.origin()` often on the same
  URL object when auth is enabled

fixes #1174
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 5, 2024
Copy link

codecov bot commented Oct 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.57%. Comparing base (f81ac53) to head (3dc9665).
Report is 250 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1175   +/-   ##
=======================================
  Coverage   95.56%   95.57%           
=======================================
  Files          30       30           
  Lines        4917     4926    +9     
  Branches      446      448    +2     
=======================================
+ Hits         4699     4708    +9     
  Misses        192      192           
  Partials       26       26           
Flag Coverage Δ
CI-GHA 95.53% <100.00%> (+<0.01%) ⬆️
MyPy 42.18% <86.36%> (+0.04%) ⬆️
OS-Linux 99.39% <100.00%> (-0.03%) ⬇️
OS-Windows 99.48% <100.00%> (-0.03%) ⬇️
OS-macOS 99.10% <100.00%> (-0.03%) ⬇️
Py-3.10.11 99.00% <100.00%> (-0.03%) ⬇️
Py-3.10.15 99.23% <100.00%> (-0.03%) ⬇️
Py-3.11.10 99.23% <100.00%> (-0.03%) ⬇️
Py-3.11.9 99.00% <100.00%> (-0.03%) ⬇️
Py-3.12.6 99.23% <100.00%> (-0.03%) ⬇️
Py-3.13.0-rc.3 99.23% <100.00%> (-0.03%) ⬇️
Py-3.8.10 98.95% <100.00%> (-0.03%) ⬇️
Py-3.8.18 99.18% <100.00%> (-0.03%) ⬇️
Py-3.9.13 98.95% <100.00%> (-0.03%) ⬇️
Py-3.9.20 99.18% <100.00%> (-0.03%) ⬇️
Py-pypy7.3.11 99.24% <100.00%> (-0.03%) ⬇️
Py-pypy7.3.16 99.23% <100.00%> (-0.03%) ⬇️
Py-pypy7.3.17 99.26% <100.00%> (-0.03%) ⬇️
VM-macos-latest 99.10% <100.00%> (-0.03%) ⬇️
VM-ubuntu-latest 99.39% <100.00%> (-0.03%) ⬇️
VM-windows-latest 99.48% <100.00%> (-0.03%) ⬇️
pytest 99.39% <100.00%> (-0.03%) ⬇️

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 bdraco merged commit cf08033 into master Oct 5, 2024
47 of 49 checks passed
@bdraco bdraco deleted the origin_speed branch October 5, 2024 14:51
@bdraco
Copy link
Member Author

bdraco commented Oct 5, 2024

from yarl import URL

import timeit

from yarl import _url

url_with_user_pass = URL("http://user:[email protected]?a+b=c+d")
url_without_user_pass = URL("http://example.com?a+b=c+d")

print(['with user/pass', timeit.timeit('url_with_user_pass.origin()', globals=globals(), number=100000)])
print(['without user/pass', timeit.timeit('url_without_user_pass.origin()', globals=globals(), number=100000)])

For testing (note that cache needs to be removed to properly test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Calling URL.origin() is expensive when we cannot avoid it in the cookie jar
1 participant