FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

concurrent.futures→asyncio state transfer is a bottleneck · Issue #134173 · python/cpython · GitHub

Repository navigation

concurrent.futures→asyncio state transfer is a bottleneck #134173

Closed

Description

Bug report

Bug description:

The current _copy_future_state implementation requires multiple method calls and lock acquisitions to retrieve the source future's state:

  1. done() - acquires lock to check state
  2. cancelled() - acquires lock again
  3. exception() - acquires lock to get exception
  4. result() - acquires lock to get result

Each method call involves thread synchronization overhead, making this operation a bottleneck for high-frequency executor dispatches.

Our use case involves dispatching a large number of small executor jobs from asyncio to a thread pool. These jobs typically involve open or stat on files that are already cached by the OS, so the actual I/O returns almost instantly. However, we still have to offload them to avoid blocking the event loop, since there's no reliable way to determine in advance whether a read will hit the cache.

As a result, the majority of the overhead isn't from the I/O itself, but from the cost of scheduling. Most of the time is spent copying future state, which involves locking. This PR reduces that overhead, which has a meaningful impact at scale.

CPython versions tested on:

3.13

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on May 18, 2025
  2. added
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    on May 18, 2025
  3. added a commit that references this issue on May 18, 2025
  4. kumaraditya303 commented on May 18, 2025

    Contributor

    Thanks

  5. moved this from Todo to Done in asyncioon May 18, 2025
  6. added a commit that references this issue on Jul 12, 2025
  7. added a commit that references this issue on Aug 4, 2025
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

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytopic-asyncio

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL