You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up calling an async function that doesn't suspend #161170
Now on await f() Python creates a coroutine object on heap and then calls coro.send(None).
If an async function doesn't suspend (directly or indirectly awaits for non-ready future in asyncio world), the coroutine is still created and send() is still called.
Very many async functions have a happy path that, for example, returns data from a memory buffer and runs I/O only if the buffer is empty. Or get an item from a queue without suspending if the queue is not empty.
The interpreter could emulate this first send(None) on the stack and lazily materialize the coroutine only if an asyc function suspends, or other conditions are met: a coroutine object is explicitly requested with immediate awaiting, C extension calls async function, an instrumentation is applied, etc.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
#91121 propose an alternative approach by introducing a new vectorcall flag.
changed the title [-]Speed up calling am async function that doesn't suspend[/-][+]Speed up calling an async function that doesn't suspend[/+]on Nov 2, 2026
Activity
pythongh-161170: Use the real issue number
pythongh-161170: Lazily materialize coroutine objects for immediate a…
[-]Speed up calling am async function that doesn't suspend[/-][+]Speed up calling an async function that doesn't suspend[/+]