Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-44337: Improve LOAD_ATTR specialization#26759

Merged
markshannon merged 5 commits intopython:mainpython/cpython:mainfrom
faster-cpython:improve-load-attr-specializationfaster-cpython/cpython:improve-load-attr-specializationCopy head branch name to clipboard
Jun 21, 2021
Merged

bpo-44337: Improve LOAD_ATTR specialization#26759
markshannon merged 5 commits intopython:mainpython/cpython:mainfrom
faster-cpython:improve-load-attr-specializationfaster-cpython/cpython:improve-load-attr-specializationCopy head branch name to clipboard

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Jun 16, 2021

We were being overly conservative by not specializing for instance attributes when the class also has an attribute.
It is OK to perform that specialization if the class attribute is not an overriding descriptor (and has an immutable class, so it will remain so).
This requires more detailed analysis of the class attribute, so this is factored out in a new function, which we can also use when we specialize STORE_ATTR.

This PR also specializes obj.__class__ using LOAD_ATTR_SLOT.

https://bugs.python.org/issue44337

* Specialize obj.__class__ with LOAD_ATTR_SLOT
* Specialize instance attribute lookup with attribute on class, provided attribute on class is not an overriding descriptor.
@markshannon
Copy link
Member Author

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly LGTM

I did not notice any logical problems or bugs. I've left a number of clarifying questions and a few minor suggestions. I do not consider any of them to be blockers, especially since this PR is an improvement regardless of my comments. However, in a couple of the cases it would be worth having a bit of discussion before merging.

Specifically:

Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
Python/specialize.c Show resolved Hide resolved
@ericsnowcurrently
Copy link
Member

Performance results: https://gist.github.com/markshannon/f938b10691f081b3a6cdad54521890fb

Any thoughts on why some of those benchmarks are showing performance regressions?

@markshannon
Copy link
Member Author

Performance results: https://gist.github.com/markshannon/f938b10691f081b3a6cdad54521890fb

Any thoughts on why some of those benchmarks are showing performance regressions?

Not really, nor why unpack_sequence is 18% faster

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for the feedback on my questions/comments. The changes make sense and analyze_descriptor() is a definite improvement.

NON_DESCRIPTOR, /* Is not a descriptor, and is an instance of an immutable class */
MUTABLE, /* Instance of a mutable class; might, or might not, be a descriptor */
ABSENT, /* Attribute is not present on the class */
__CLASS__, /* __class__ attribute */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would worry this (__CLASS__) would be a used or reserved name in some C implementation. Identifiers with __ are generally reserved by the C std.

@markshannon markshannon reopened this Jun 21, 2021
@markshannon markshannon merged commit fb68791 into python:main Jun 21, 2021
@markshannon markshannon deleted the improve-load-attr-specialization branch January 6, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.