Skip to content

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Apr 16, 2025

Before we can specialize GET_ITER, or even decide if it is worth specializing GET_ITER, we need stats.

@brandtbucher
Copy link
Member

I bet a lot of the "other" will already be iterators. It may be worth adding a stat at the end, before "other", for types where tp->tp_iter == PyObject_SelfIter. At least for that case we can specialize it and do nothing.

(I wish we could also "unwrap" list, tuple, and range iterators, similar in spirit to our method call optimization. Basically, if GET_ITER encounters a list_iterator, range_iterator, or tuple_iterator we just put the container itself and the current index on the stack. But that's not safe to do if its refcount is greater than one, unfortunately.)

@markshannon markshannon merged commit 622300b into python:main Apr 29, 2025
63 checks passed
@markshannon markshannon deleted the get-iter-stats branch April 29, 2025 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants