Skip to content

gh-162784: Add list fast path for STORE_SLICE and slice helpers - #162785

Open
josh-hurst wants to merge 1 commit into
python:mainfrom
josh-hurst:perf/list-store-slice-fastpath
Open

josh-hurst wants to merge 1 commit into
python:mainfrom
josh-hurst:perf/list-store-slice-fastpath

Conversation

@josh-hurst

Copy link
Copy Markdown

Route STORE_SLICE on exact lists directly to list assignment. For equal-length replacements of up to 32 items from another exact list or tuple, store all new references before releasing the old ones. The slice helpers also unpack compact integers directly and skip division for unit steps.

Across five paired M4 Pro runs, median fannkuch(9) time fell from 191.765 ms to 162.340 ms. One million eight-item assignments fell from 27.546 ms to 14.476 ms. Self-assignment differed by less than 0.1% on the paired median. Debug and free-threaded tests passed, including reference-leak checks.

Found and written by an AI optimization pipeline I run; I reviewed every line, ran the tests and sanitizers, and can answer for it.

STORE_SLICE list fast path

Skip the temporary slice for exact lists. Stage displaced references for
equal-length replacements of up to 32 items and release them after all
writes. Preserve bound finalization order and iterable conversion errors.

Slice helpers

Unpack compact integer bounds directly and use a difference to count
unit-step slices after normalization.
@python-cla-bot

python-cla-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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