GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Speed up calling an async function that doesn't suspend · Issue #161170 · python/cpython

Speed up calling an async function that doesn't suspend #161170

New issue
Copy link
New issue
Copy link
Open
Open
Speed up calling an async function that doesn't suspend#161170
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@asvetlov
asvetlov
opened on Nov 2, 2026
Issue body actions

Feature or enhancement

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.

Linked PRs

  • gh-161170: Lazily materialize coroutine objects for immediate awaits #161171

Activity

  1. asvetlov
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Nov 2, 2026
  2. asvetlov
    added 2 commits that reference this issue on Nov 2, 2026

    pythongh-161170: Use the real issue number

    e1ad90f

    pythongh-161170: Lazily materialize coroutine objects for immediate a…

    e3e43cb
  3. NekoAsakura
    added
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 2, 2026
  4. terryjreedy
    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.