GH-96421: Insert shim frame on entry to interpreter
Simplifies RETURN_VALUE, RETURN_GENERATOR and YIELD_VALUE as they no longer need to check if the current frame is the entry frame.
Should allow specialization of FOR_ITER and SEND for generators and coroutines.
Needs docs and news.
Performance impact is about zero
- Issue: gh-96421
Does this add much extra CPU/stack/memory overhead for calling Python from C? Or alternating py/c/py/c/py calls? Probably not the most important use-cases, but I would hope that they wouldn't pessimize too much.
Does this add much extra CPU/stack/memory overhead for calling Python from C?
- CPU: A little, but it speeds up the return sequence. The net effect is about zero
- C Stack consumption is increased, but only 80 bytes per call.
The performance impact of this negative but I want to merge anyway because:
- The more negative benchmarks seem to use generators a fair bit, e.g https://github.com/python/pyperformance/blob/main/pyperformance/data-files/benchmarks/bm_nqueens/run_benchmark.py#L27 This PR is an enabler of optimizing entering and exiting generators and coroutines, so we would expect a win in the longer term on those benchmarks.
- I expect further benefits from this change once https://github.com/python/cpython/pull/93221 is merged.
- In the long term we expect calls to
_PyEval_EvalFrameDefault()to become rare, as we move more control into bytecode.
When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.
I have made the requested changes; please review again
Thanks for making the requested changes!
@brandtbucher: please review the changes made to this pull request.
I don't know if I'll have time to review again today (still need to prepare my talk for the release stream). Is this able to wait until next week? If not, I can try to make time.
It can wait until next week
:robot: New build scheduled with the buildbot fleet by @markshannon for commit d1136553cdb64119da4cf890785eda8675ce2963 :robot:
If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.