You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagetype-featureA feature request or enhancement
List slice assignment builds a temporary slice even when the target is an exact list and the replacement has the same length. This shows up in fannkuch, which repeatedly reverses short prefixes. On an M4 Pro, a prototype reduced median fannkuch(9) time from 191.765 ms to 162.340 ms across five paired runs.
Found and written by an AI optimization pipeline I run; I reviewed every line, ran the tests and sanitizers, and can answer for it.
Please share benchmarks. How does it impact pyperformance suite for instance? is it in a PGO/LTO build? what's the actual geometric mean of various test cases? we need more evidence before making performance changes. I don't know how often we replace a list's slice with the same length though. It may be too specific for a task.
I reran this on PGO+LTO builds (--enable-optimizations --with-lto, base d88a6b9c3e, M4 Pro, Clang 21.0.0). Across 57 zero-dep pyperformance benchmarks, the geomean is 1.01x faster (1.0066x), almost all from fannkuch (172 ms -> 145 ms, 1.18x faster). Without it, the other 56 are flat (1.0037x).
Honestly, I agree the same-length <= 32 special case is too narrow to carry just for fannkuch, and good catch on the FT refcounts in #162785 (_STORE_SLICE shouldn't be stealing start/stop). _BINARY_SLICE right above it just borrows the indices and hands exact lists off to a ~20-line _PyList_BinarySlice helper. Would a minimal _PyList_StoreSlice mirroring that (just calling list_ass_slice, no same-length special case or sliceobject.c changes) be worth measuring? If STORE_SLICE on lists still feels too narrow either way, no worries, happy to close this out.
Would a minimal _PyList_StoreSlice mirroring that (just calling list_ass_slice, no same-length special case or sliceobject.c changes) be worth measuring
That's not me who should answer. As the issue submitter, you should decide what you want to submit. I would say yes in this case, but this kind of question (that looks like an LLM one) is something you (as a hman) should be able to answer on your side.
As a matter of fact, I don't think we need a special path for storing slices. It's a rare operation anyway, so I will close this issue.
interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagetype-featureA feature request or enhancement
Activity
picnixz commentedon Nov 28, 2026
Please share benchmarks. How does it impact pyperformance suite for instance? is it in a PGO/LTO build? what's the actual geometric mean of various test cases? we need more evidence before making performance changes. I don't know how often we replace a list's slice with the same length though. It may be too specific for a task.
josh-hurst commentedon Nov 28, 2026
I reran this on PGO+LTO builds (
--enable-optimizations --with-lto, based88a6b9c3e, M4 Pro, Clang 21.0.0). Across 57 zero-dep pyperformance benchmarks, the geomean is1.01x faster(1.0066x), almost all fromfannkuch(172 ms -> 145 ms,1.18x faster). Without it, the other 56 are flat (1.0037x).Microbenchmarks (
-p 20 -w 1 -n 3):Full pyperformance results (57 zero-dep benchmarks, PGO+LTO)
Microbenchmark script (bm_list_store_slice_micro.py)
Honestly, I agree the same-length
<= 32special case is too narrow to carry just forfannkuch, and good catch on the FT refcounts in #162785 (_STORE_SLICEshouldn't be stealingstart/stop)._BINARY_SLICEright above it just borrows the indices and hands exact lists off to a ~20-line_PyList_BinarySlicehelper. Would a minimal_PyList_StoreSlicemirroring that (just callinglist_ass_slice, no same-length special case orsliceobject.cchanges) be worth measuring? IfSTORE_SLICEon lists still feels too narrow either way, no worries, happy to close this out.picnixz commentedon Nov 29, 2026
That's not me who should answer. As the issue submitter, you should decide what you want to submit. I would say yes in this case, but this kind of question (that looks like an LLM one) is something you (as a hman) should be able to answer on your side.
As a matter of fact, I don't think we need a special path for storing slices. It's a rare operation anyway, so I will close this issue.