GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-131798: Add tier-2 list specialization for STORE_SLICE by eendebakpt · Pull Request #149446 · python/cpython

Conversation

@eendebakpt

@eendebakpt eendebakpt commented May 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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
  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
eendebakpt and others added 4 commits May 5, 2026 21:17
@eendebakpt @claude
bytecodes: add tier-2 _STORE_SLICE_LIST optimizer specialization
5748806
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) <[email protected]>
@eendebakpt
remove speculative guards
3ee86eb
@eendebakpt
add bytearray slice assignments
a2f6b84
@eendebakpt
fix memory leak
dacab18
@eendebakpt
eendebakpt requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners May 6, 2026 07:32
@bedevere-app bedevere-app Bot mentioned this pull request May 6, 2026
Better uop coverage in the JIT optimizer #131798
Open
@bedevere-app bedevere-app Bot added the awaiting review label May 6, 2026
@eendebakpt
remove bytearray opcode
dede9fa
@read-the-docs-community

read-the-docs-community Bot commented May 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35284756 | 📁 Comparing 0bc13a1 against main (970b043)

  🔍 Preview build  

1 file changed
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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
@eendebakpt
add news entry
e9f81cb
@eendebakpt @claude
Merge branch 'main' into fannkuch_store_slice_tier2
0a93906
Resolved generated pycore_uop_ids.h conflict by regenerating from
bytecodes.c / optimizer_bytecodes.c.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@eendebakpt
add PyAPI_FUNC
2988266
markshannon
markshannon reviewed May 22, 2026
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

One question, otherwise looks good.

It would be good to optimize constant slices, but that would need a change to the bytecode compiler. For another PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

eendebakpt
eendebakpt commented May 22, 2026
View reviewed changes
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

eendebakpt and others added 2 commits May 22, 2026 15:08
@eendebakpt
Apply suggestion from @eendebakpt
ba66173
@eendebakpt @claude
Regenerate optimizer_cases.c.h
0bc13a1
Picks up the dead-local removal from the latest commit
('Apply suggestion from @eendebakpt') in optimizer_bytecodes.c.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@eendebakpt

eendebakpt commented Jun 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

One question, otherwise looks good.

It would be good to optimize constant slices, but that would need a change to the bytecode compiler. For another PR.

Ah yes. So the mechanism is: for x[1:2] = ... there is a constant slice. The compiler optimizes this to LOAD_CONST and STORE_SUBSCR (which is not specialized), which means we will never get to the specialized STORE_SLICE introduced in this PR.

We could:

  1. Skip the optimization now that STORE_SLICE has more specializations (compiler change).
  2. Specialize STORE_SUBSCR for lists (and more types?)

I am leaning towards the second option (initially only in tier2 to avoid adding a tier1 opcode).

Update: a branch with STORE_SUBSCR specialized is main...eendebakpt:cpython:gh-131798-store-subscr-list-slice, but there is hardly any performance gain.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eendebakpt
eendebakpt requested a review from markshannon June 2, 2026 12:30
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 5, 2026
@ambv

ambv commented Oct 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR is superseded by #157011, a newer open pull request for the same issue (gh-131798), and it no longer merges cleanly. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer.

Sorry, incorrectly flagged as a duplicate.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv closed this Oct 20, 2026
@ambv ambv reopened this Oct 21, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 21, 2026
@savannahostrowski
savannahostrowski removed their request for review October 21, 2026 03:11
@eendebakpt

eendebakpt commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

This is is a jit optimization, so closing for now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eendebakpt eendebakpt closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review stale Stale PR or inactive for long period of time. type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@eendebakpt @ambv @markshannon
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.