gh-145685: Improve scaling of type attribute lookups#145774
gh-145685: Improve scaling of type attribute lookups#145774colesbury wants to merge 2 commits intopython:mainfrom
Conversation
Avoid locking in the PyType_Lookup cache-miss path if the type's tp_version_tag is already valid.
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 68c122c 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145774%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
mpage
left a comment
There was a problem hiding this comment.
Would it be worth adding a test case to the scaling benchmark?
| END_TYPE_LOCK(); | ||
| } | ||
| else { | ||
| res = find_name_in_mro(type, name, out); |
There was a problem hiding this comment.
Do we need to hold the type lock around this?
There was a problem hiding this comment.
The operations in find_name_in_mro are individually thread-safe, although this allows for mutations to types to be interleaved with the MRO traversal. I think that's acceptable. There were already edge cases where that could happen due to ensure_shared_on_read() calls suspending the critical section during dictionary lookups in find_name_in_mro.
Importantly, if any type in the MRO chain is modified during lookup, the assigned version tag will be stale so any future cache lookups won't use it.
This improves the scaling behavior, but it's not enough to scale linearly so I don't want to add a benchmark to ftscalingbench.py yet. Here's the benchmark I've occasionally used locally: https://gist.github.com/colesbury/7d43e7dde89c1cb5574b5a2c73cc52b1 Some of the remaining issues:
|
Avoid locking in the PyType_Lookup cache-miss path if the type's tp_version_tag is already valid.
_PyType_Lookup/_PyType_LookupStackRefAndVersion#145685