Repository navigation
Conversation
Could you benchmark the case where I'm interested in whether this branch is really necessary. If the performance is comparable, there's no need to keep the existing code path. If there's a significant difference, I'd also like to reconsider the similar code in |
|
I tried making Some
The difference is small for less sparse cases, but the fallback is noticeably faster once almost all entries have been deleted. Both implementations passed the targeted dict tests, watcher tests, and the sparse-dict stress checks. I used the same Ubuntu 24.04 runner for each comparison, with measurements in A–B–B–A order. The benchmark and workflow are available here: https://github.com/localzet/cpython/actions/runs/42595205328 The GCC PGO/LTO comparison is still running, so these numbers are from the regular build. For now, I'd keep the density check. I'll look at |
Summary
Copy live entries directly into a compact keys table when cloning a sparse combined dictionary, rather than inserting each surviving key/value pair through the generic merge path.
__hash__methods again.dict.copy()and copying into empty dictionaries (includingfrozendictconstruction).Tests
The patch was tested in the contributor fork with:
test_dict,test_capi.test_dict, andtest_capi.test_watchers(249 tests).-R 3:3on these modules.detect_leaks=0, matching CPython's ASan CI configuration).Verification: https://github.com/localzet/cpython/actions/runs/42510556632
Performance
Linux x86-64, GCC PGO + LTO; median of repeated
source.copy()measurements against the unmodified baseline (3c92a06e). Times are ns per operation.These are results from one CI benchmark run, not a statistically controlled multi-machine study. Extremely sparse integer-key cases are approximately unchanged; some cases show a small measured slowdown.
Benchmark: https://github.com/localzet/cpython/actions/runs/42497448717
AI assistance was used for source exploration, patch development, and test/benchmark automation. The patch and its behavior were examined and tested against the configurations listed above.