Content-Length: 290285 | pFad | https://redirect.github.com/pypa/packaging/issues/1058

F9C perf: 10% faster stripping zeros by henryiii · Pull Request #1058 · pypa/packaging · GitHub
Skip to content

perf: 10% faster stripping zeros#1058

Merged
henryiii merged 3 commits intopypa:mainfrom
henryiii:henryiii/pref/simplerzeros
Jan 14, 2026
Merged

perf: 10% faster stripping zeros#1058
henryiii merged 3 commits intopypa:mainfrom
henryiii:henryiii/pref/simplerzeros

Conversation

@henryiii
Copy link
Contributor

@henryiii henryiii commented Jan 14, 2026

This is faster than the current version, and a bit simpler. Suggested by ℤahlman on discord a while back; I thought it would be slower so I didn't try it till now. I found a way to improve it to be faster, actually, and more like the previous version but inline. I had the function primarily for the early return, but this avoids that, making it faster I think in the common case where a zero does not need to be stripped, due to the removed function call.

It also removes the function added in 26.0 _strip_trailing_zeros, which is why it might be worth putting in now, to keep people from depending on that (private) function? I'm perfectly fine to leave it till after 26.0 final, though, since we are in RC phase. Not that anyone would depend on something with a leading underscore. What do other people think? It's about 10% faster hashing and 5% faster sorting.

Edit: found a problem in the asv benchmarks; .setup is not rerun between samples, so caching needs to be cleared. Fixing this shows this is a bit faster.

All benchmarks:

Change Before [350a230] After [b699ea0] <henryiii/pref/simplerzeros> Ratio Benchmark (Parameter)
2.29±0.01ms 2.30±0.02ms 1 markers.TimeMarkerSuite.time_constructor
816±60μs 801±3μs 0.98 markers.TimeMarkerSuite.time_evaluate
9.44±0.06ms 9.37±0.03ms 0.99 requirement.TimeRequirementSuite.time_constructor
588±6μs 588±5μs 1 resolver.TimeResolverSuite.time_resolver_loop
3.31±0.02ms 3.30±0.01ms 1 specifiers.TimeSpecSuite.time_constructor
4.08±0.2ms 3.91±0.04ms 0.96 specifiers.TimeSpecSuite.time_contains
61.5±2μs 60.4±0.04μs 0.98 specifiers.TimeSpecSuite.time_filter
4.07±0.03μs 4.03±0.08μs 0.99 utils.TimeUtils.time_canonicalize_name
1.99±0.06ms 1.96±0ms 0.99 version.TimeVersionSuite.time_constructor
- 1.04±0ms 935±5μs 0.9 version.TimeVersionSuite.time_hash
2.21±0.01ms 2.11±0ms 0.95 version.TimeVersionSuite.time_sort
723±10μs 704±7μs 0.97 version.TimeVersionSuite.time_str

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii henryiii changed the title perf: try simpler zeros perf: 10% faster stripping zeros Jan 14, 2026
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii henryiii merged commit 716beb1 into pypa:main Jan 14, 2026
40 checks passed
@henryiii henryiii deleted the henryiii/pref/simplerzeros branch January 14, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://redirect.github.com/pypa/packaging/issues/1058

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy