Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-143658: Usestr.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalized#144083
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
hugovk wants to merge1 commit intopython:mainChoose a base branch fromhugovk:3.15-importlib.metadata-normalized
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Uh oh!
There was an error while loading.Please reload this page.
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
….metadata.Prepared.normalizedCo-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
str.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalizedstr.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalizedhauntsaninja approved these changesJan 20, 2026
MemberAuthor
hugovk commentedJan 22, 2026
sergey-miryanov approved these changesJan 23, 2026
Contributor
sergey-miryanov 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.
LGTM
brettcannon approved these changesJan 23, 2026
Sign up for freeto 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.



Uh oh!
There was an error while loading.Please reload this page.
Follow on from#143660 which replaced
re.subwithstr.translate.@henryiii discovered that whilst that is an improvement on Python 3.10-3.11 and 3.14, the performance of
str.translateis much worse on Python 3.12 and 3.13, and can be worse than the originalre.sub.Further, his fix inpypa/packaging#1064 to replace
str.translatewithstr.lowerandstr.replacecalls is better than both the other options across all Python versions, to varying degrees.I benchmarked all three across all available Python Build Standalone versions from 3.10-3.15 on macOS:
I also benchmarked Windows and Ubuntu it's the same pattern.
Whilst the improvement isn't as large for CPython 3.15 as it is for libraries such as
packagingthat support a wide range of Pythons,importlib.metadatadoes have a backport, and I'll updatepython/importlib_metadata#529 once this is merged.str.translateto improve performance ofimportlib.metadata.Prepared.normalized#143658