Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork94
Usestr.translate to improve performance ofnormalize#529
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
Draft
hugovk wants to merge1 commit intopython:mainChoose a base branch fromhugovk:speedup-normalize
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.
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
MemberAuthor
hugovk commentedJan 19, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Following on frompypa/packaging#1064, Python 3.12 and 3.13 are slower, even though 3.10, 3.11 and 3.14 are much faster. Measured with hyperfine on python.org versions on macOS:
Marking as draft for now. Details❯hyperfine --warmup 1 -r 3 \ -n main --prepare 'git checkout main' 'python3.10 benchmark_names.py' \ -n PR --prepare 'git checkout speedup-normalize -q' 'python3.10 benchmark_names.py'Benchmark 1: main Time (mean ± σ): 6.632 s ± 0.515 s [User: 6.138 s, System: 0.359 s] Range (min … max): 6.237 s … 7.214 s 3 runsBenchmark 2: PR Time (mean ± σ): 3.456 s ± 0.122 s [User: 3.257 s, System: 0.169 s] Range (min … max): 3.373 s … 3.596 s 3 runsSummary PR ran 1.92 ± 0.16 times faster than mainimportlib_metadata on speedup-normalize [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 42s❯hyperfine --warmup 1 -r 3 \ -n main --prepare 'git checkout main' 'python3.11 benchmark_names.py' \ -n PR --prepare 'git checkout speedup-normalize -q' 'python3.11 benchmark_names.py'Benchmark 1: main Time (mean ± σ): 6.331 s ± 0.541 s [User: 5.415 s, System: 0.420 s] Range (min … max): 5.859 s … 6.921 s 3 runsBenchmark 2: PR Time (mean ± σ): 3.302 s ± 0.031 s [User: 3.023 s, System: 0.209 s] Range (min … max): 3.273 s … 3.334 s 3 runsSummary PR ran 1.92 ± 0.16 times faster than mainimportlib_metadata on speedup-normalize [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 38s❯hyperfine --warmup 1 -r 3 \ -n main --prepare 'git checkout main' 'python3.12 benchmark_names.py' \ -n PR --prepare 'git checkout speedup-normalize -q' 'python3.12 benchmark_names.py'Benchmark 1: main Time (mean ± σ): 5.690 s ± 0.183 s [User: 5.281 s, System: 0.274 s] Range (min … max): 5.492 s … 5.852 s 3 runsBenchmark 2: PR Time (mean ± σ): 6.640 s ± 0.069 s [User: 6.169 s, System: 0.296 s] Range (min … max): 6.560 s … 6.688 s 3 runsSummary main ran 1.17 ± 0.04 times faster than PRimportlib_metadata on speedup-normalize [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 50s❯hyperfine --warmup 1 -r 3 \ -n main --prepare 'git checkout main' 'python3.13 benchmark_names.py' \ -n PR --prepare 'git checkout speedup-normalize -q' 'python3.13 benchmark_names.py'Benchmark 1: main Time (mean ± σ): 5.784 s ± 0.109 s [User: 5.359 s, System: 0.253 s] Range (min … max): 5.674 s … 5.891 s 3 runsBenchmark 2: PR Time (mean ± σ): 5.957 s ± 0.074 s [User: 5.601 s, System: 0.241 s] Range (min … max): 5.876 s … 6.022 s 3 runsSummary main ran 1.03 ± 0.02 times faster than PRimportlib_metadata on speedup-normalize [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 50s❯hyperfine --warmup 1 -r 3 \ -n main --prepare 'git checkout main' 'python3.14 benchmark_names.py' \ -n PR --prepare 'git checkout speedup-normalize -q' 'python3.14 benchmark_names.py'Benchmark 1: main Time (mean ± σ): 5.749 s ± 0.060 s [User: 5.442 s, System: 0.223 s] Range (min … max): 5.684 s … 5.802 s 3 runsBenchmark 2: PR Time (mean ± σ): 2.163 s ± 0.125 s [User: 1.922 s, System: 0.169 s] Range (min … max): 2.020 s … 2.257 s 3 runsSummary PR ran 2.66 ± 0.16 times faster than main |
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.
This is the same aspython/cpython#143660.
We can apply@henryiii's improvement to
packaginginpypa/packaging#1030 (see alsohttps://iscinumpy.dev/post/packaging-faster/) to improve the performance ofnormalizeand make it ~3.7 times faster.Benchmark
Run
Prepared.normalize(n)on every name in PyPI:Benchmark data can be found athttps://gist.github.com/hugovk/efdbee0620cc64df7b405b52cf0b6e42
Before
After
3.7 times faster.