-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-143658: Use str.lower and replace to further improve performance of importlib.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
….metadata.Prepared.normalized Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
str.lower and replace to further improve performance of importlib.metadata.Prepared.normalizedstr.lower and replace to further improve performance of importlib.metadata.Prepared.normalized
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
|
This |
|



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 in pypa/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 update python/importlib_metadata#529 once this is merged.str.translateto improve performance ofimportlib.metadata.Prepared.normalized#143658