-
Notifications
You must be signed in to change notification settings - Fork 49
Use str.translate to improve performance of normalize_name
#254
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
Draft
hugovk
wants to merge
2
commits into
pypa:master
Choose a base branch
from
hugovk:speedup-canonicalize_name
base: master
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.
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]>
Author
|
Following on from pypa/packaging#1064, this is slower with 3.12 and 3.13, so marking as draft for now. Testing on Python 3.8 to 3.14 on macOS (python.org versions) using hyperfine:
Details❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.8 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.8 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 7.699 s ± 0.620 s [User: 6.703 s, System: 0.455 s]
Range (min … max): 7.054 s … 8.290 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 4.620 s ± 0.040 s [User: 4.381 s, System: 0.199 s]
Range (min … max): 4.574 s … 4.650 s 3 runs
Summary
PR ran
1.67 ± 0.14 times faster than master
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 49s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.9 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.9 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 7.463 s ± 0.480 s [User: 6.627 s, System: 0.416 s]
Range (min … max): 7.111 s … 8.009 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 4.775 s ± 0.131 s [User: 4.379 s, System: 0.296 s]
Range (min … max): 4.679 s … 4.924 s 3 runs
Summary
PR ran
1.56 ± 0.11 times faster than master
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 50s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.10 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.10 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 6.042 s ± 0.019 s [User: 5.561 s, System: 0.329 s]
Range (min … max): 6.021 s … 6.054 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 3.947 s ± 0.213 s [User: 3.503 s, System: 0.311 s]
Range (min … max): 3.751 s … 4.174 s 3 runs
Summary
PR ran
1.53 ± 0.08 times faster than master
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 41s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.11 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.11 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 5.437 s ± 0.144 s [User: 4.972 s, System: 0.274 s]
Range (min … max): 5.279 s … 5.563 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 3.598 s ± 0.144 s [User: 3.198 s, System: 0.265 s]
Range (min … max): 3.463 s … 3.750 s 3 runs
Summary
PR ran
1.51 ± 0.07 times faster than master
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 43s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.12 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.12 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 5.707 s ± 0.358 s [User: 5.005 s, System: 0.369 s]
Range (min … max): 5.439 s … 6.113 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 6.907 s ± 0.059 s [User: 6.439 s, System: 0.331 s]
Range (min … max): 6.846 s … 6.963 s 3 runs
Summary
master ran
1.21 ± 0.08 times faster than PR
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 48s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.13 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.13 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 5.248 s ± 0.067 s [User: 4.906 s, System: 0.226 s]
Range (min … max): 5.183 s … 5.316 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 6.479 s ± 0.163 s [User: 6.002 s, System: 0.315 s]
Range (min … max): 6.328 s … 6.652 s 3 runs
Summary
master ran
1.23 ± 0.03 times faster than PR
distlib on speedup-canonicalize_name [?] via 🐍 v3.14.2 via 💎 v3.1.3 took 31s
❯ hyperfine --warmup 1 -r 3 \
-n master --prepare 'git checkout master' 'python3.14 benchmark_names_distlib.py' \
-n PR --prepare 'git checkout speedup-canonicalize_name -q' 'python3.14 benchmark_names_distlib.py'
Benchmark 1: master
Time (mean ± σ): 5.784 s ± 0.605 s [User: 5.174 s, System: 0.275 s]
Range (min … max): 5.370 s … 6.478 s 3 runs
Benchmark 2: PR
Time (mean ± σ): 2.391 s ± 0.061 s [User: 2.067 s, System: 0.223 s]
Range (min … max): 2.321 s … 2.431 s 3 runs
Summary
PR ran
2.42 ± 0.26 times faster than master |
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 ofnormalize_nameand make it ~3.4 times faster.Benchmark
Run
normalize_name(n)on every name in PyPI:Benchmark data can be found at https://gist.github.com/hugovk/efdbee0620cc64df7b405b52cf0b6e42
Before
With Python 3.14 on macOS:
After
3.4 times faster.