-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-96793: Change FOR_ITER
to not pop the iterator on exhaustion.
#96801
Conversation
With the tweaks to skip the |
Python/specialize.c
Outdated
SPECIALIZATION_FAIL(FOR_ITER, | ||
_PySpecialization_ClassifyIterator(iter)); | ||
goto failure; | ||
if (_Py_OPCODE(instr[INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1]) == POP_TOP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it not be POP_TOP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler did something clever.
I don't know what that might be, but I don't want to rely on the compiler not transforming the code.
I'm considering changing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
|
|
|
…on. (pythonGH-96801) Change FOR_ITER to have the same stack effect regardless of whether it branches or not. Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
Requires an additional
POP_TOP
at the end of the loop. By itself, this would be a pointless change, but as part of #96793 it makes sense.Pyperformance shows a 1% slowdown but I suspect that is a bit noisy. The 11% slowdown of
unpack_sequence
makes no sense.Given the dispatching overhead is in the 10-15% and
FOR_ITER
represents 1-2% of instructions executed we would expect at worst a 0.3% slowdown.I will get performance numbers for the whole of #96793 before merging the parts.
for gen():
, and awaiting coroutines,await coro()
#96793