Title: Leverage eager tasks to optimize asyncio gather & TaskGroups further · Issue #104144 · python/cpython · GitHub
Open Graph Title: Leverage eager tasks to optimize asyncio gather & TaskGroups further · Issue #104144 · python/cpython
X Title: Leverage eager tasks to optimize asyncio gather & TaskGroups further · Issue #104144 · python/cpython
Description: 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(...)), ...
Open Graph Description: 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...
X Description: 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...
Opengraph URL: https://github.com/python/cpython/issues/104144
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Leverage eager tasks to optimize asyncio gather \u0026 TaskGroups further","articleBody":"# Feature or enhancement\r\n\r\ngh-97696 introduced eager tasks factory, which speeds up some async-heavy workloads by up to 50% when opted in.\r\n\r\ninstalling 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.:\r\n\r\n```\r\nasyncio.get_event_loop().set_task_factory(asyncio.eager_task_factory)\r\n\r\nawait asyncio.gather(coro1, coro2, coro3)\r\n\r\nasync with asyncio.TaskGroup() as tg:\r\n tg.create_task(coro1)\r\n tg.create_task(coro2)\r\n tg.create_task(coro3)\r\n```\r\n\r\nin 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.\r\n\r\nthe 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.\r\n\r\napplications that use multiple levels of nested gathers / TaskGroups can benefit significantly from eagerly completing multiple levels without blocking.\r\n\r\nthis can be achieved by modifying the implementation of `gather` and `TaskGroup` to detect when it can complete without blocking, and skip scheduling wakeup \u0026 done callbacks.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104140\n* gh-104138\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/itamaro","@type":"Person","name":"itamaro"},"datePublished":"2023-05-03T22:43:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/104144/cpython/issues/104144"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:de16305b-6cde-cbfd-1a85-32fc2eb02903 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAB8:26E310:10B82C4:170ECFC:6969F5A3 |
| html-safe-nonce | 3d8838626e942a5e842e28bd7ec5618df8cf3588d181eff06a95b944bafb7808 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUI4OjI2RTMxMDoxMEI4MkM0OjE3MEVDRkM6Njk2OUY1QTMiLCJ2aXNpdG9yX2lkIjoiMjQ0MTg1NTIyNjU5NTIxOTU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ab6003a3428f2ce19cb8a79a294e387569c559d88a1f8067a758d5ec22cb3fdf |
| hovercard-subject-tag | issue:1694945693 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/104144/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4dbe14529154b523146a34a450a344eb1b6d00d5953c72c980b6143dfd0134f8/python/cpython/issues/104144 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4dbe14529154b523146a34a450a344eb1b6d00d5953c72c980b6143dfd0134f8/python/cpython/issues/104144 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | itamaro |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width