Repository navigation
Conversation
`await f()` on an async def, and async def __aenter__() and __aexit__() of async with, no longer create a coroutine object unless the body suspends. The compiler pushes a NULL lazy_outcome below the callable and follows the call with the new END_AWAITED_CALL instruction, which continues with GET_AWAITABLE, skips the SEND loop if the body returned, or creates the coroutine and jumps to YIELD_VALUE if it suspended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pop the yielded value from the caller's stack, fire PY_THROW, and allow CLEANUP_THROW in a lazily run body. Make the MemoryError tests target the coroutine allocation and cover a body that catches the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GET_AWAITABLE after an awaited call now has the GET_AWAITABLE_AWAITED_CALL flag (4) in its oparg, next to 'where' in the low two bits, and handles the lazy outcome itself. The SEND loop always starts right after it, so the target of the suspended case needs no offset in the oparg and GET_AWAITABLE is not a jump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
asvetlov
requested review from
1st1,
AA-Turner,
Fidget-Spinner,
ZeroIntensity,
iritkatriel,
kumaraditya303,
markshannon and
willingc
as code owners
November 23, 2026 07:58
Documentation build overview
15 files changed ·
|
Indexing the slot through lazy_outcome[(oparg >> 2) & 1] made its load wait for oparg, which slowed down awaits that suspend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Don't let f_lineno jumps land on the awaited-call GET_AWAITABLE. * Don't make YIELD_VALUE a line start; emit the await line's LINE event from GET_AWAITABLE after materializing, so a raising callback is not handled as a throw into the awaited coroutine. * Never line-instrument the awaited-call GET_AWAITABLE as a jump target. * Allow the lazy coroutine's exception state to start a new data stack chunk. * Skip LLTRACE_RESUME_FRAME on a lazy suspension. * Publish the materialized coroutine's frame state after re-pointing its frame object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep the await's line for GET_AWAITABLE after an awaited call, so tracebacks don't depend on whether LINE monitoring was ever set up; the SEND after it starts the line. * Allow INSTRUCTION events at that GET_AWAITABLE, making the call eager, and skip the event if instrumentation was enabled while a lazy body ran. * Emit the await's LINE event before the lazy body runs, as the eager path does at SEND, and forbid jumps from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* PyFrame_GetGenerator() returns None, not NULL, without a generator. * The awaited-call flag of GET_AWAITABLE is the value 4, not bit 4. * Don't warn that lazy_outcome is unused when asserts are disabled. * Skip test_memory_error_before_body_runs without _testcapi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A running lazy coroutine body now has owner FRAME_OWNED_BY_LAZY_CORO instead of a lazy_coro state bit, so returning from an ordinary function no longer checks for it: _PyEval_FrameClearAndPop dispatches on the owner it already tests. The new value is 4, keeping the existing values that outside tools rely on, so range checks against FRAME_OWNED_BY_INTERPRETER become equality checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A coroutine that is awaited as soon as it is called (
await f()), and anasync def__aenter__()or__aexit__()ofasync with, no longer creates a coroutine object unless it suspends. Awaits that complete immediately become about twice as fast.After an awaited call the compiler emits
GET_AWAITABLEwith the newGET_AWAITABLE_AWAITED_CALL=4flag in its oparg; the low two bits keep thewherevalue. When the flag is set, theCALLfamily may run a coroutine body without creating the coroutine object, andGET_AWAITABLEhandles the outcome:SENDloop if inlined call returns a valueYIELD_VALUEif inlined call suspends. The
SENDloop always starts right afterGET_AWAITABLE, so no offset is stored andGET_AWAITABLEstays a non-jump instruction. New*_AWAITEDspecializations ofCALLandCALL_KWcover awaited calls of Python functions.Until such a coroutine first suspends,
frame.f_generatorisNone.Calls from C, profiling and monitoring of calls, PEP 523, coroutine origin tracking and the JIT keep the current behavior.
await noop()async with asyncio.Lock()(Median of three runs; all three builds measured side by side. Percentages are relative to main.)
A plain Python call that is not awaited executes 2–4 more machine instructions (under 1%): returning from a function now checks whether its frame is a lazily run coroutine body.
Supersedes #162267.
🤖 Generated with Claude Code