cpython icon indicating copy to clipboard operation
cpython copied to clipboard

GH-96421: Insert shim frame on entry to interpreter

Open markshannon opened this issue 3 years ago • 9 comments

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

markshannon avatar Aug 26 '22 17:08 markshannon

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.

sweeneyde avatar Sep 08 '22 17:09 sweeneyde

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.

markshannon avatar Sep 09 '22 16:09 markshannon

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.

markshannon avatar Oct 20 '22 15:10 markshannon

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

bedevere-bot avatar Oct 20 '22 23:10 bedevere-bot

I have made the requested changes; please review again

markshannon avatar Oct 21 '22 16:10 markshannon

Thanks for making the requested changes!

@brandtbucher: please review the changes made to this pull request.

bedevere-bot avatar Oct 21 '22 16:10 bedevere-bot

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.

brandtbucher avatar Oct 21 '22 17:10 brandtbucher

It can wait until next week

markshannon avatar Oct 21 '22 17:10 markshannon

: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.

bedevere-bot avatar Nov 08 '22 11:11 bedevere-bot