-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143658: importlib.metadata: Use str.translate to improve performance of importlib.metadata.Prepared.normalized
#143660
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
hugovk
merged 7 commits into
python:main
from
hugovk:3.15-importlib.metadata-canonicalize_name
Jan 13, 2026
Merged
gh-143658: importlib.metadata: Use str.translate to improve performance of importlib.metadata.Prepared.normalized
#143660
hugovk
merged 7 commits into
python:main
from
hugovk:3.15-importlib.metadata-canonicalize_name
Jan 13, 2026
+52
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-Authored-By: Henry Schreiner <[email protected]>
translate to improve performance of canonicalize_nametranslate to improve performance of canonicalize_name
picnixz
reviewed
Jan 10, 2026
Misc/NEWS.d/next/Library/2026-01-10-15-40-57.gh-issue-143658.Ox6pE5.rst
Outdated
Show resolved
Hide resolved
translate to improve performance of canonicalize_namestr.translate to improve performance of importlib.metadata.Prepared.normalized
Co-authored-by: Bénédikt Tran <[email protected]>
picnixz
reviewed
Jan 10, 2026
Member
picnixz
left a comment
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.
Do we have tests actually? if not, maybe it'd be good to add some.
Co-authored-by: Bénédikt Tran <[email protected]>
johnslavik
reviewed
Jan 10, 2026
Member
johnslavik
left a comment
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.
Small ideas
Co-authored-by: Bartosz Sławecki <[email protected]>
a12k
reviewed
Jan 10, 2026
hauntsaninja
approved these changes
Jan 13, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We can apply @henryiii's improvement to
packagingin pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance ofcanonicalize_nameand make it ~3.7 times faster.Benchmark
Run
Prepared.normalize(n)on every name in PyPI:Benchmark data can be found at https://gist.github.com/hugovk/efdbee0620cc64df7b405b52cf0b6e42
Before
With optimisations:
After
3.7 times faster.
str.translateto improve performance ofimportlib.metadata.Prepared.normalized#143658