Title: gh-104144: Optimize gather to finish eagerly when all futures complete eagerly by itamaro · Pull Request #104138 · python/cpython · GitHub
Open Graph Title: gh-104144: Optimize gather to finish eagerly when all futures complete eagerly by itamaro · Pull Request #104138 · python/cpython
X Title: gh-104144: Optimize gather to finish eagerly when all futures complete eagerly by itamaro · Pull Request #104138 · 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 gathering futures (asyncio.gather(...)), e.g.: asyncio.get_event_loop().set_task_factory(asyncio.eager_task_factory) await asyncio.gather(coro1, coro2, 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 eager uses callbacks internally that end up getting scheduled to the event loop even if all the futures were able to finish synchronously, and blocking the coroutine in which gather() was awaited, preventing the task from completing eagerly even if otherwise it could. applications that use multiple levels of nested gathers can benefit significantly from eagerly completing multiple levels without blocking, as implemented in this PR by skipping scheduling done callbacks for futures that are already done (e.g. finished eagerly). Benchmarks this makes the async pyperformance benchmarks up to 3x faster (!!), using a patch to pyperformance that adds "eager" flavors 3.12-base.20230503.async.4.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 23:27:23.329046 End date: 2023-05-03 23:46:37.706326 3.12-nogf.20230503.async.2.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 23:05:45.011427 End date: 2023-05-03 23:22:44.908094 +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | Benchmark | 3.12-base.20230503.async.4.json | 3.12-nogf.20230503.async.2.json | Change | Significance | +===============================+=================================+=================================+==============+========================+ | async_tree_cpu_io_mixed | 868 ms | 859 ms | 1.01x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager | 391 ms | 129 ms | 3.03x faster | Significant (t=209.74) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_cpu_io_mixed | 756 ms | 490 ms | 1.54x faster | Significant (t=167.41) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_io | 1.51 sec | 1.50 sec | 1.00x faster | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_eager_memoization | 595 ms | 314 ms | 1.89x faster | Significant (t=70.25) | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_io | 1.39 sec | 1.40 sec | 1.00x slower | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_memoization | 677 ms | 683 ms | 1.01x slower | Not significant | +-------------------------------+---------------------------------+---------------------------------+--------------+------------------------+ | async_tree_none | 575 ms | 574 ms | 1.00x 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 gathering futures (asy...
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 gathering futures (asy...
Opengraph URL: https://github.com/python/cpython/pull/104138
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:a258e507-8e67-9ea0-43ea-82fbeb09ab5a |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | D13A:247E0C:40FAAE:5AB98B:696A7551 |
| html-safe-nonce | e4f45ba563815c29f33bf4e7708da65fe2fb0a562839030c0f344129a614cbe3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTNBOjI0N0UwQzo0MEZBQUU6NUFCOThCOjY5NkE3NTUxIiwidmlzaXRvcl9pZCI6IjYyMzQ1ODUyNzQ2NTAzNTkxMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ae2c415cf423e2d8cabc5c3deceaa50e9cc52ce1c2f2f96afdb92fa683ef2893 |
| hovercard-subject-tag | pull_request:1337117158 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,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/104138/checks |
| 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 gathering futures (asy... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cfa223d62d272274e0b68350b4bd7741f3ca7498b8c4b8b1bc1e6deabbdbc09d |
| 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 full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6a0b6893c221f98f607598e939299fdf5763435d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width