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 — Leverage eager tasks to optimize asyncio gather & TaskGroups further · Issue #104144 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Leverage eager tasks to optimize asyncio gather & TaskGroups further#104144
Copy link
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asynciotype-featureA feature request or enhancementA feature request or enhancement

Description

@itamaro
itamaro
opened on May 3, 2023
Issue body actions

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 a TaskGroup, 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 both gather and TaskGroup 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 which gather or TaskGroup() 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 of gather and TaskGroup to detect when it can complete without blocking, and skip scheduling wakeup & done callbacks.

Linked PRs

  • gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly #104140
  • gh-104144: Optimize gather to finish eagerly when all futures complete eagerly #104138

Activity

  1. itamaro
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on May 3, 2023
  2. gvanrossum
    added a commit that references this issue on May 5, 2023

    gh-104144: Skip scheduling a done callback if a TaskGroup task comple…

    52d8f36
  3. kumaraditya303
    added a commit that references this issue on May 6, 2023

    gh-104144: Optimize gather to finish eagerly when all futures complet…

    263abd3
  4. kumaraditya303
    closed this as completedon May 6, 2023
  5. kumaraditya303
    added
    performancePerformance or resource usagePerformance or resource usage
    topic-asyncio
    3.12only security fixesonly security fixes
    on May 6, 2023
  6. jbower-fb
    added 2 commits that reference this issue on May 8, 2023

    pythongh-104144: Skip scheduling a done callback if a TaskGroup task …

    0b9d0b2

    pythongh-104144: Optimize gather to finish eagerly when all futures c…

    cb70222
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

    3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asynciotype-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.