Skip to content

gh-131798: Add tier-2 list specialization for STORE_SLICE#149446

Open
eendebakpt wants to merge 8 commits intopython:mainfrom
eendebakpt:fannkuch_store_slice_tier2
Open

gh-131798: Add tier-2 list specialization for STORE_SLICE#149446
eendebakpt wants to merge 8 commits intopython:mainfrom
eendebakpt:fannkuch_store_slice_tier2

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

@eendebakpt eendebakpt commented May 6, 2026

The JIT currently dispatches STORE_SLICE (container[start:stop] = value) through PyObject_SetItem even when the trace has proven the container is an exact list. Adding a tier-2 specialization _STORE_SLICE_LIST skips the slice-object allocation and the generic lookup.

The optimizer rewrites _STORE_SLICE_STORE_SLICE_LIST only when the container's type is statically known, so non-list callers and tier-1 are unaffected. A second commit for bytearray was added but reverted.

Benchmark results on pyperformance fannkuch (tier-2 / JIT enabled):

main (252 ± 3 ms)  ->  PR (223 ± 2 ms):  1.13x faster

eendebakpt and others added 4 commits May 5, 2026 21:17
Adds a tier-2 only `_STORE_SLICE_LIST` op and a guard `_GUARD_THIRD_LIST`,
plus an optimizer rule that rewrites generic `_STORE_SLICE` to the list
fast path when the LHS container is (or can be guarded as) an exact list.

The list path calls a new `_PyList_StoreSlice` helper that adjusts the
slice indices and dispatches into `list_ass_slice_lock_held` directly,
skipping the slice-object allocation and the generic
`PyObject_SetItem` lookup.

The tier-1 `_STORE_SLICE` opcode is left unchanged so non-list callers
incur no extra branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 6, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32557155 | 📁 Comparing e9f81cb against main (970b043)

  🔍 Preview build  

43 files changed · ± 42 modified · - 1 deleted

± Modified

- Deleted

@eendebakpt eendebakpt changed the title gh-131798: Add tier2 coverage for STORE_SLICE gh-131798: Add tier-2 list specialization for STORE_SLICE May 6, 2026
eendebakpt and others added 3 commits May 6, 2026 09:44
Resolved generated pycore_uop_ids.h conflict by regenerating from
bytecodes.c / optimizer_bytecodes.c.

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