Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Leverage eager tasks to optimize asyncio gather & TaskGroups further #104144

Closed
Labels
3.12only security fixesperformancePerformance or resource usagetopic-asynciotype-featureA feature request or enhancement
@itamaro

Description

@itamaro

Feature or enhancement

gh-97696 introduced eager tasks factory, which speeds up some async-heavy workloads by up to 50% when opted in.

installing the eager tasks factory applies out-of-the-box when gathering tasks (asyncio.gather(...)), and when creating tasks as part of aTaskGroup, e.g.:

asyncio.get_event_loop().set_task_factory(asyncio.eager_task_factory)await asyncio.gather(coro1, coro2, coro3)async with asyncio.TaskGroup() as tg:    tg.create_task(coro1)    tg.create_task(coro2)    tg.create_task(coro3)

in both examples,coro{1,2,3} will eagerly execute the first step, and potentially complete without scheduling to the event loop if the coros don't block.

the implementation of bothgather andTaskGroup uses callbacks internally that end up getting scheduled to the event loop even if all the tasks were able to finish synchronously, and blocking the coroutine in whichgather orTaskGroup() was awaited, preventing from the task to complete eagerly even if otherwise it could.

applications that use multiple levels of nested gathers / TaskGroups can benefit significantly from eagerly completing multiple levels without blocking.

this can be achieved by modifying the implementation ofgather andTaskGroup to detect when it can complete without blocking, and skip scheduling wakeup & done callbacks.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesperformancePerformance or resource usagetopic-asynciotype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp