Skip to content

gh-152063: Cache the offset of the inline values 'valid' byte in LOAD_ATTR#153122

Draft
Aniketsy wants to merge 1 commit into
python:mainfrom
Aniketsy:fix-152063
Draft

gh-152063: Cache the offset of the inline values 'valid' byte in LOAD_ATTR#153122
Aniketsy wants to merge 1 commit into
python:mainfrom
Aniketsy:fix-152063

Conversation

@Aniketsy

@Aniketsy Aniketsy commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes to _LOAD_ATTR_INSTANCE_VALUE and the specializer look good.
There should be no reason to increase the cache size for LOAD_ATTR, there is already spare space in LOAD_ATTR_INSTANCE_VALUE

typedef struct {
_Py_BackoffCounter counter;
uint16_t type_version[2];
uint16_t value_offset;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't need changing

Comment thread Python/bytecodes.c
macro(LOAD_ATTR) =
_SPECIALIZE_LOAD_ATTR +
unused/8 +
unused/9 +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cache is already large enough.
If you reduce the size of the unused cache in LOAD_ATTR_INSTANCE_VALUE by one, the other specializations don't need to change.

Comment thread Python/specialize.c
cache->index = (uint16_t)offset;
write_u32(cache->version, tp_version);
if (base_op == LOAD_ATTR) {
Py_ssize_t valid_offset = (char *)&values->valid - (char *)owner;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Py_ssize_t valid_offset = (char *)&values->valid - (char *)owner;
Py_ssize_t validity_offset = (char *)&values->valid - (char *)owner;

valid_offset sounds like a bool for whether the offset is valid.

@bedevere-app

bedevere-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

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.

The LOAD_ATTR_INSTANCE_VALUE instruction can be sped up by storing the offset of the valid field in the cache.

2 participants