You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Eliminate overhead of fetching and testing NULL attributes in STORE_ATTR specializations for new objects #144141
classC:
def__init__(self, a, b, c):
self.a=aself.b=bself.c=cC(1,2,3)
This produces a trace looking something like this:
...
_CHECK_AND_ALLOCATE_OBJECT
_CREATE_INIT_FRAME
_PUSH_FRAME
# Some guards
_LOAD_FAST_BORROW_1
_LOAD_FAST_BORROW_0
# Some more guards
_STORE_ATTR_INSTANCE_VALUE
# Some more guards
_LOAD_FAST_BORROW_2
_LOAD_FAST_BORROW_0
# Some more guards
_STORE_ATTR_INSTANCE_VALUE
# Some more guards
_LOAD_FAST_BORROW_3
_LOAD_FAST_BORROW_0
# Some more guards
_STORE_ATTR_INSTANCE_VALUE
...
Each of those _STORE_ATTR_INSTANCE_VALUE reads the old value out of memory and then conditionally decrefs it.
But in this case we know that the old value was NULL so we can just overwrite it.
So we can replace this:
As a mechanism for achieving this we can add a new jit optimizer type that tracks the NULLness of its attributes.
It would need to track when it was last modified, to check for escapes, and one bit of information for each slot.
uint8_ttag;
uint8_tslot_state[9]; // Handles up to 72 slots, which should be plenty for most classes.uint16_tlast_modified_uop;
uint32_ttype_version; // Can use this to remove some of those guards
@cocolato your __slots__ PR can already do this. It needs a bit of adjusting to track escapes, but tracking the types of something in slots is a superset of tracking the nullness of the slot.
@markshannon let's use #144122 to achieve this. I already discussed with @cocolato on the issue that we should do this. It's a useful thing to have.
Activity
markshannon commentedon Jan 22, 2026
As a mechanism for achieving this we can add a new jit optimizer type that tracks the
NULLness of its attributes.It would need to track when it was last modified, to check for escapes, and one bit of information for each slot.
cocolato commentedon Jan 22, 2026
If needed, I can try to implement it.
Fidget-Spinner commentedon Jan 22, 2026
@cocolato your
__slots__PR can already do this. It needs a bit of adjusting to track escapes, but tracking the types of something in slots is a superset of tracking the nullness of the slot.@markshannon let's use #144122 to achieve this. I already discussed with @cocolato on the issue that we should do this. It's a useful thing to have.
__slots__object and its property in the Tier 2 optimizer #144145 as a duplicate of this issue