| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Co-authored-by: Carl Meyer <carl@oddbird.net>
There was a problem hiding this comment.
LGTM.
How sure are you that skipping the set-name call if name is None is always correct? (It seems fine to me, but in theory some 3rd party task implementation could do other stuff there.)
Sorry, something went wrong.
I don't know about all possible 3p task implementations. At least looking at uvloop, it seems it uses asyncio.Task directly. |
Sorry, something went wrong.
|
I don't think it will be measurable -- it looks to be a very minor part of creating a task (even more so with gh-103767). It just is one more thing we'd have to put in what's new (and it's not covered by the PR title :-). |
Sorry, something went wrong.
|
agreed, let me revert that part! |
Sorry, something went wrong.
| @@ -0,0 +1 @@ | |||
| Optimize :class:`asyncio.TaskGroup` when using :func:`asyncio.eager_task_factory`. Skip scheduling done callbacks when all tasks finish without blocking. | |||
There was a problem hiding this comment.
Hmm actually the scheduling is skipped on a per task basis rather than when all tasks finish without blocking.
Sorry, something went wrong.
There was a problem hiding this comment.
I have a fix in itamaro@ac1ee82 (PR depends on gh-104251 first)
Sorry, something went wrong.
…completes eagerly (python#104140) Co-authored-by: Carl Meyer <carl@oddbird.net>
| Back | FazBrowse Home | New Git URL |
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 creating tasks as part of a TaskGroup, e.g.:
asyncio.get_event_loop().set_task_factory(asyncio.eager_task_factory) async with asyncio.TaskGroup() as tg: tg.create_task(coro1) tg.create_task(coro2) tg.create_task(coro3)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 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 TaskGroup() was awaited, preventing the task from completing eagerly even if otherwise it could.
applications that use multiple levels of nested TaskGroups can benefit significantly from eagerly completing multiple levels without blocking, as implemented in this PR by skipping scheduling the done callback if the future is done.
Benchmarks
this makes the async pyperformance benchmarks up to 4x faster (!!), using a patch to pyperformance that adds "eager" flavors and uses TaskGroups instead of gather