Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:main
base:main
Choose a base branch
Loading
fromhugovk:3.15-importlib.metadata-normalized

Conversation

@hugovk
Copy link
Member

@hugovkhugovk commentedJan 20, 2026
edited by bedevere-appbot
Loading

Follow on from#143660 which replacedre.sub withstr.translate.

@henryiii discovered that whilst that is an improvement on Python 3.10-3.11 and 3.14, the performance ofstr.translate is much worse on Python 3.12 and 3.13, and can be worse than the originalre.sub.

Further, his fix inpypa/packaging#1064 to replacestr.translate withstr.lower andstr.replace calls 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:

image

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 aspackaging that support a wide range of Pythons,importlib.metadata does have a backport, and I'll updatepython/importlib_metadata#529 once this is merged.

….metadata.Prepared.normalizedCo-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
@hugovkhugovk added performancePerformance or resource usage topic-importlib labelsJan 20, 2026
@hugovkhugovk changed the titlegh-143660: Usestr.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalizedgh-143658: Usestr.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalizedJan 20, 2026
@hugovk
Copy link
MemberAuthor

Attached code for benchmarking and making the chart, and the results data from my macOS machine:

bench.zip

And charts and data of benchmarking on macOS, Ubuntu and Windows via GitHub Actions:

all-macOS-latestall-ubuntu-latestall-windows-latest

macos-ubuntu-windows.zip

Copy link
Contributor

@sergey-miryanovsergey-miryanov 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 freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@brettcannonbrettcannonbrettcannon approved these changes

@sergey-miryanovsergey-miryanovsergey-miryanov approved these changes

@hauntsaninjahauntsaninjahauntsaninja approved these changes

@jaracojaracoAwaiting requested review from jaracojaraco is a code owner

@warsawwarsawAwaiting requested review from warsawwarsaw is a code owner

Assignees

No one assigned

Labels

awaiting mergeperformancePerformance or resource usagetopic-importlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@hugovk@brettcannon@sergey-miryanov@hauntsaninja

[8]ページ先頭

©2009-2026 Movatter.jp