Skip to content

Store insertion order using offsets#149901

Open
eendebakpt wants to merge 5 commits into
python:mainfrom
eendebakpt:delta_encoding_jit
Open

Store insertion order using offsets#149901
eendebakpt wants to merge 5 commits into
python:mainfrom
eendebakpt:delta_encoding_jit

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

No description provided.

eendebakpt and others added 5 commits May 15, 2026 20:06
…tion order

- Add test_racing_store_attr_insertion_order: concurrent attribute stores
  with natural and reverse order
- Add test_racing_store_attr_delete_reinsert: concurrent delete + re-insert
- Trim stale comments about skip-write optimization

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A sequential attribute store -- the common case in __init__ -- appends
at index == values->size, so the insertion-order delta is 0.  Since the
insertion-order array slots at or beyond values->size are kept zero,
that write can be skipped: _STORE_ATTR_INSTANCE_VALUE now checks
index == values->size and just bumps values->size in that case.

Keeping those slots zero requires initialising and maintaining them:

* _PyObject_InitInlineValues now zeroes the insertion-order array.  Not
  every allocator memsets the inline-values region -- _PyObject_GC_New
  (used for TypeVar and friends) does not, only _PyType_AllocNoTrack
  does -- so the array could otherwise start with garbage.
* clear_embedded_values (the embedded path of dict.clear()) re-zeroes
  the array; previously it reset values->size without clearing it.
* delete_index_from_values already re-zeroes the vacated slot.

The _PyDictValues_AddToInsertionOrderDelta helper is no longer needed
and is removed; the non-sequential path uses _PyDictValues_AddToInsertionOrder.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add the tier-2-only uop _STORE_ATTR_INSTANCE_VALUE_NO_ORDER and teach
the JIT optimiser to emit it.  When an object is freshly produced by
_ALLOCATE_OBJECT, the optimiser tracks its inline values->size
statically: each _STORE_ATTR_INSTANCE_VALUE that stores to the next
sequential slot is proven to have insertion-order delta 0, so the whole
insertion-order bookkeeping (helper call, delta computation, array
write) collapses to a single "values->size = N" store.

Tracking is dropped on any escaping uop that could hand the object to
code mutating its inline values; the store macro's own uops and _POP_TOP
are exempt (the object is not yet reachable by user code).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant