Skip to content

perf: Cache Version hash value in dedicated slot#1118

Merged
notatallshaw merged 3 commits intopypa:mainfrom
notatallshaw:perf/cache-hash-value
Mar 13, 2026
Merged

perf: Cache Version hash value in dedicated slot#1118
notatallshaw merged 3 commits intopypa:mainfrom
notatallshaw:perf/cache-hash-value

Conversation

@notatallshaw
Copy link
Copy Markdown
Member

I'm surprised CPython isn't doing this automatically? But this appeared to make a difference locally.

@notatallshaw
Copy link
Copy Markdown
Member Author

Faster warm hash:

| -        | 283±5μs              | 169±0.5μs           |    0.6  | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.10-PYTHONHASHSEED0]              |
| -        | 210±3μs              | 108±1μs             |    0.51 | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.11-PYTHONHASHSEED0]              |
| -        | 218±5μs              | 130±0.9μs           |    0.6  | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.12-PYTHONHASHSEED0]              |
| -        | 235±2μs              | 137±2μs             |    0.58 | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.13-PYTHONHASHSEED0]              |
| -        | 181±7μs              | 130±2μs             |    0.72 | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.14-PYTHONHASHSEED0]              |
| -        | 334±2μs              | 223±2μs             |    0.67 | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.8-PYTHONHASHSEED0]               |
| -        | 315±4μs              | 200±1μs             |    0.63 | version.TimeVersionSuite.time_hash_warm [runnervm0kj6c/virtualenv-py3.9-PYTHONHASHSEED0]               |

Interestingly this moves Python 3.11 into the lead for fastest warm hash, most microbenchmarks show Python 3.14 in the lead at everything.

@notatallshaw
Copy link
Copy Markdown
Member Author

I think this change might actually make the warm Version hash benchmark fairly pointless, I doubt we can ever get faster than a slotted cache look up.

@henryiii
Copy link
Copy Markdown
Contributor

We can drop it later, would be nice to at least get a plot of it over time first.

@notatallshaw notatallshaw force-pushed the perf/cache-hash-value branch from 1576e48 to 2393a78 Compare March 12, 2026 23:20
@henryiii
Copy link
Copy Markdown
Contributor

I doubt we can ever get faster

Makes it faster...

@notatallshaw notatallshaw merged commit 1676a10 into pypa:main Mar 13, 2026
56 checks passed
ngoldbaum pushed a commit to ngoldbaum/packaging that referenced this pull request Apr 1, 2026
This was referenced Apr 13, 2026
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