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
{{ message }}
Repository navigation
[PERF]: Handle generic sequences more efficiently #1640
elementStrides[idx] here uses the generic PySequence_GetItem, which first must check whether the sequence is a list or tuple before getting the item. This check is performed repeatedly for each item, even though the type of the sequence remains constant. The branch predictor may or may not be able to smooth this out.
Ideally, we would use the PySequence_Fast family of functions. Unfortunately, Cython's wrappers of low-level Python/C API functions involving borrowing are broken -- we would probably need to revert to raw C snippets to make that work.
Alternatively, we could do something like:
if type(seq) is list:
for idx in range(len(seq)):
# use cpython.PyList_GetItemInt...
elif type(seq) is tuple:
for idx in range(len(seq)):
# use cpython.PyTuple_GetItemInt...
Activity
mdboom commentedon Apr 28, 2026
This will be best handled after the cython-gen/cybind merge.