GeezerVison is showing github.com — gh-87729: improve hit rate of LOAD_SUPER_ATTR specialization by carljm · Pull Request #104270 · python/cpython
Conversation
carljm
commented
May 7, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
We observed that in stats collection on pyperformance (+ pyston macro-benchmarks), the hit rate of the LOAD_SUPER_ATTR specialization to LOAD_SUPER_ATTR_METHOD was not as good as expected. Investigation revealed a few causes for this.
-
It is not uncommon to have super method calls that use argument unpacking (e.g. super().method(*args, **kwargs)) and so need to use e.g. CALL_FUNCTION_EX. This fails the checks for the load-method optimization in the compiler, so it emits a LOAD_SUPER_ATTR without the load-method optimization.
-
Loading things that are not actually method descriptors via a call that looks like super().method() is also not uncommon. E.g. super().__new__() where the base class is e.g. builtin str.
-
The type of self at a particular call-site of super() is commonly polymorphic, whenever the inheritance chain is longer than length 2. E.g. if C inherits B inherits A, then a call to super() in a method of B may commonly see self of type either B or C.
The fixes to (1) and (2) are simple enough: we should also specialize for LOAD_SUPER_ATTR_ATTR.
(3) is a much trickier problem, since it means we can't inline-cache the results of a super() lookup at all. The results of a super() lookup are dependent on the type of self, and we can't effectively specialize for the type of self (barring polymorphic inline caching, which we don't generally do and would make for a much large inline cache.)
This means that specialization of LOAD_SUPER_ATTR is just splitting out the "shadowed global super" case from the load-method and attr cases. This still preserves most of the performance improvement from LOAD_SUPER_ATTR, which always came from avoiding allocation of single-use super objects.
With this change, in my tests the hit rate of LOAD_SUPER_ATTR specialization in pyperformance is 100%. (Effectively this just means we don't have a case in pyperformance of shadowing the name super.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I think this is fine for 3.12.
For 3.13 we will probably want something like we had before. With larger regions of optimization which handle polymorphism through code duplication prior to specialization, we will want the information about what the value of super().attr is.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yes, I agree; once we have a reasonable way to handle specialization in polymorphic cases, we'll want to reintroduce this. But for now I don't think we can keep it; it results in too many failed specializations.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
carljm reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|