Title: gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly by itamaro · Pull Request #104140 · python/cpython · GitHub
Open Graph Title: gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly by itamaro · Pull Request #104140 · python/cpython
X Title: gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly by itamaro · Pull Request #104140 · python/cpython
Description: 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 3.12-base.20230503.async.3.json =============================== Performance version: 1.0.7 Python version: 3.12.0a7+ (64-bit) revision da1980afcb Report on Linux-5.15.0-1033-aws-x86_64-with-glibc2.31 Number of logical CPUs: 72 Start date: 2023-05-03 22:18:14.628900 End date: 2023-05-03 22:36:35.397630 3.12-tgcb.20230503.async.3.json =============================== Performance version: 1.0.7 Python version: 3.12.0a7+ (64-bit) revision 5397cd9f62 Report on Linux-5.15.0-1033-aws-x86_64-with-glibc2.31 Number of logical CPUs: 72 Start date: 2023-05-03 22:38:45.960219 End date: 2023-05-03 22:54:49.008951 +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | Benchmark | 3.12-base.20230503.async.3.json | 3.12-tgcb.20230503.async.3.json | Change | Significance | +===============================+=================================+=================================+==============+========================+ | async_tree_cpu_io_mixed | 843 ms | 827 ms | 1.02x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager | 383 ms | 92.9 ms | 4.12x faster | Significant (t=189.26) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_cpu_io_mixed | 708 ms | 412 ms | 1.72x faster | Significant (t=180.43) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_io | 1.40 sec | 1.39 sec | 1.01x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_memoization | 515 ms | 232 ms | 2.22x faster | Significant (t=183.24) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_io | 1.37 sec | 1.35 sec | 1.01x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_memoization | 644 ms | 634 ms | 1.01x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_none | 517 ms | 508 ms | 1.02x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ Issue: gh-104144
Open Graph Description: 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...
X Description: 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...
Opengraph URL: https://github.com/python/cpython/pull/104140
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9b20d31e-8b2f-0b1d-a640-083f313b7dc0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ACB6:25F5D0:3FA96A:569AB3:6969AE4A |
| html-safe-nonce | a4f33cc1a2b00b1bc75822f856fdf3ddcfba69327d6ed85b0b2a9fc73237d6bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0I2OjI1RjVEMDozRkE5NkE6NTY5QUIzOjY5NjlBRTRBIiwidmlzaXRvcl9pZCI6Ijk1MjA0NDc5MDcyNDgwMDA3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 59b2907cd3910c77f1cf777acf0172c2a21e7cfd9c6671581ca3b90de7568686 |
| hovercard-subject-tag | pull_request:1337141007 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/104140/files |
| twitter:image | https://avatars.githubusercontent.com/u/290943?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/290943?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width