gh-153486: Factor non-negative compact int subscript guards#153487
gh-153486: Factor non-negative compact int subscript guards#153487KRRT7 wants to merge 5 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
I ran a fresh set of perf checks for this on a Linux VM, rebuilding both I used a medium
Other differences were either not significant or did not reproduce on rerun ( |
|
I dug into the negative-index case further and found that the important change here is at specialization time, not just in the specialized opcode body. With this update, list subscripts using exact compact negative ints can specialize to I then measured two focused microbenchmarks that exercise that case directly:
L = list(range(100))
idx = -1
x = L[idx]
L = list(range(100))
idxs = (42, -1) * 100
def f(L, idxs):
s = 0
for idx in idxs:
s += L[idx]
return sPinned
So the win here is specifically for list subscript sites that use negative compact int indices and can now remain specialized. |
|
Why only lists, not tuples or strings? It is easier to keep specialization and execution consistent if specialization is just by compactness, not by sign, for all specializations. |
well, one question on scope: this PR currently covers the list negative-index specialization follow-up since it directly regressed the cases being optimized. For the other related specializations in this area, would you prefer they be folded into this PR as well, or handled in a separate follow-up PR? |
This reverts commit 7b711cc.
|
answered my own question there by splitting up the work based on what they were doing, I've opened #153487 with the intention that this PR gets merged first. |
Factor a dedicated non-negative compact-int guard into the specialized subscript/store-subscript fast paths for
list,tuple, andstr.This makes the specialization contract explicit and removes redundant checks from the specialized bodies. Negative indices still fall back to the generic path.
Issue: gh-153486