Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-145481: Optimize frozendict lookup in free threading#145482
gh-145481: Optimize frozendict lookup in free threading#145482vstinner wants to merge 2 commits intopython:mainfrom
Conversation
vstinner commentedMar 3, 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.
According the benchmark below, Benchmark results:
Benchmark hidden because not significant (1): int keys Benchmark results compared to the regular build (ref):
Python built in release mode, Benchmark run on my Fedora 43 laptop which has 12 threads (6 CPU cores). |
colesbury commentedMar 3, 2026
The string benchmark has really bad scaling because the strings aren't interned so we have reference count contention, plus some other things means that we also fall back to the locking code path. Most dicts (and presumably frozendicts) use string literals as keys, which are interned and immortalized and avoid this problem. You can see this if you update the benchmark: frozendict_str_keys=frozendict({'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}) On my machine, I'm not seeing an improvement with this PR for string literals keys or ints. In fact, it's slightly worse, which is surprising. (Maybe something weird with branch predictor behavior?) main (671a953)PR + frozendict_str_keys literals |
Uh oh!
There was an error while loading.Please reload this page.