Skip to content

gh-95865: Speed up urllib.parse.quote_from_bytes() #95872

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

Merged
merged 2 commits into from
Aug 31, 2022

Conversation

sweeneyde
Copy link
Member

@sweeneyde sweeneyde commented Aug 11, 2022

Roughly 1.8x faster:

.\python.bat -m pyperf timeit -s "from urllib.parse import quote_from_bytes as f; b = b'A'*10_000 + b'='" "f(b)"

Before: Mean +- std dev: 570 us +- 6 us
After:  Mean +- std dev: 309 us +- 3 us

@mdboom mdboom added the performance Performance or resource usage label Aug 11, 2022
@sweeneyde sweeneyde requested a review from orsenthil August 30, 2022 18:43
@@ -906,7 +906,7 @@ def quote_from_bytes(bs, safe='/'):
if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe):
return bs.decode()
quoter = _byte_quoter_factory(safe)
return ''.join([quoter(char) for char in bs])
return ''.join(map(quoter, bs))
Copy link
Member

Choose a reason for hiding this comment

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

Very interesting.

Copy link
Member

@orsenthil orsenthil left a comment

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants