-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
GH-93533: Shrink the LOAD_ATTR caches
#103014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LOAD_ATTR caches.LOAD_ATTR caches
|
So if I'm understanding this correctly, for each class only 16 methods/attributes can be specialised, with everything after just failing? If so 16 seems fairly small, especially for larger libraries/applications. Something like |
Correct (not including instance attributes). I definitely prefer a growable cache to this approach, except that the numbers we have are slower. I'm also open to using a larger number of entries, like 32 or 64, if others feel similarly. |
|
I'm also not sure if this causes problems for interpreter isolation. Maybe putting this sort of state on static built-in types is a bad idea, whether it's resizable or not. |
|
(Docs now passing now #103019 is merged, and updating this with |
|
From a correctness point of view, adding the cache to static classes should be fine. All the attributes of superclasses of static classes must also be static. However, we would like static classes to be |
|
Closing because of the various issues outlined above. |
This adds a fixed array of cached methods to the
PyTypeObjectstruct. This approach saves memory if there are ~23x moreLOAD_ATTRsites than there are types.A size of 16 was chosen because:
LOAD_ATTRhit rate onpyperformance, with 32.5% of specialization failures due to a too-small cache.LOAD_ATTRhit rate onpyperformance, with 8.7% of specialization failures due to a too-small cache.LOAD_ATTRhit rate onpyperformance, with 3.3% of specialization failures due to a too-small cache.A flexible buffer was also considered, but that was 1% slower, likely due to the additional indirection and management of the buffer.
LOAD_ATTRis too large. #93533