Currently, we specialize FOR_ITER for both tuple and list. We also handle tuple and lists specially in GET_ITER to support this specialization.
We should extend this specialization of iteration over sequences, using virtual iterators to bytes, str, bytesarray and others.
To do this, we should:
- Add a
tp_getiteritem slots to PyTypeObject for sequences that can be efficiently indexed and cannot raise except for out-of-bounds access.
- Add a specialization of
FOR_ITER for these classes.
- Specialize
GET_ITER for:
- iterators
- indexable sequences (those classes with a
tp_getiteritem slot)
- Specialize
SEND for indexable sequences which should also improve JIT coverage, as unspecialized _SEND is currently a major cause of jit optimization failures.
Combined with #145667 this will allow effective specialization of a wider range of iterables and allow that specialization not only for for loops, but also for yield from loops.
It will add 3 instructions (4 new, 1 removed) which a reasonable
Linked PRs
Currently, we specialize
FOR_ITERfor both tuple and list. We also handle tuple and lists specially inGET_ITERto support this specialization.We should extend this specialization of iteration over sequences, using virtual iterators to
bytes,str,bytesarrayand others.To do this, we should:
tp_getiteritemslots toPyTypeObjectfor sequences that can be efficiently indexed and cannot raise except for out-of-bounds access.FOR_ITERfor these classes.GET_ITERfor:tp_getiteritemslot)SENDfor indexable sequences which should also improve JIT coverage, as unspecialized_SENDis currently a major cause of jit optimization failures.Combined with #145667 this will allow effective specialization of a wider range of iterables and allow that specialization not only for
forloops, but also foryield fromloops.It will add 3 instructions (4 new, 1 removed) which a reasonable
Linked PRs