gh-153486: Factor non-negative compact int subscript guards#153487
gh-153486: Factor non-negative compact int subscript guards#153487KRRT7 wants to merge 4 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. |
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