Skip to content

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

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

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

@StanFromIreland

Copy link
Copy Markdown
Member

Please post the benchmark script. Also please benchmark with PyPerformance.

@picnixz picnixz closed this Nov 28, 2026
@picnixz

picnixz commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Until the questions I asked on the issue are resolved, I don't think we should make that change. It's not clear whether this is a niche case or not and how this impacts other benchmarks. There also seem to have incref-decref contentions that are not free on the FT build.

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.

3 participants