Repository navigation
Conversation
Add CALL_PY_ASYNC_EXACT_ARGS, CALL_PY_ASYNC_GENERAL, CALL_BOUND_METHOD_ASYNC_EXACT_ARGS and CALL_BOUND_METHOD_ASYNC_GENERAL. They apply to coroutine functions whose code starts with RETURN_GENERATOR; POP_TOP, and create the coroutine object directly instead of pushing a frame and executing RETURN_GENERATOR. The new coroutine's frame is left at the POP_TOP, as RETURN_GENERATOR leaves it.
Add CALL_KW_PY_ASYNC and CALL_KW_BOUND_METHOD_ASYNC, which create the coroutine directly for keyword calls of the same simple coroutine functions as the CALL_*_ASYNC specializations.
Member
IMO, I don't think adding bytecodes is worth it for little gains, that aren't actually going to be beneficial in practice. |
Specialize calls of generator and async generator functions as well as coroutine functions, and rename the opcodes from *_ASYNC to *_GEN: CALL_PY_GEN_EXACT_ARGS, CALL_PY_GEN_GENERAL, CALL_BOUND_METHOD_GEN_EXACT_ARGS, CALL_BOUND_METHOD_GEN_GENERAL, CALL_KW_PY_GEN and CALL_KW_BOUND_METHOD_GEN. Only require the code to start with RETURN_GENERATOR: the new frame is left at the following instruction, as RETURN_GENERATOR leaves it, so that instruction does not need to be checked. _Py_MakeCoro now delegates to _PyGen_NewFromFunction(), which takes the caller frame used to compute cr_origin.
Contributor
Author
|
@StanFromIreland in general, I agree with you. On the other hand, if we implement #162920 proposal, new specializations couldn't require new opcodes; we can specialize broader than we do it now. Anyway, consider it as my work-in-progress experiment, which is definitely not ready for landing yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling a generator, coroutine or async generator function today goes through
CALL_PY_EXACT_ARGS/CALL_PY_GENERAL(orCALL_KW_PY): a frame is pushed,RETURN_GENERATORallocates the generator object, copies the frame into it, pops the frame and returns to the caller.This adds specializations that build the generator object directly at the call site:
CALL_PY_GEN_EXACT_ARGSCALL_PY_GEN_GENERALCALL_BOUND_METHOD_GEN_EXACT_ARGSCALL_BOUND_METHOD_GEN_GENERALCALL_KW_PY_GENCALL_KW_BOUND_METHOD_GENThey apply to functions whose code starts with
RETURN_GENERATOR, so functions with aMAKE_CELL/COPY_FREE_VARSprefix keep the current path. The function version guard covers later__code__changes.The new object's frame is initialized in place and left at the instruction after
RETURN_GENERATOR, the same stateRETURN_GENERATORleaves it in, so the send, throw andFOR_ITER_GENpaths are unchanged._Py_MakeCoronow delegates to_PyGen_NewFromFunction(), which takes the caller frame; coroutine origin tracking is computed from it.Instructions and cycles per iteration, PGO+LTO build, x86-64,
perf stat, user space:await noop()c = noop(); await cawait o.meth(1)(with a default)next(gen())for _ in gen(): passfor _ in gen(1, k=2): passawaita coroutine that suspends onceThe pyperformance async benchmarks were within noise on this machine.