Store insertion order using offsets#149901
Open
eendebakpt wants to merge 5 commits into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.