-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-100344: Provide C implementation for asyncio.current_task #100345
Merged
kumaraditya303
merged 11 commits into
python:main
from
itamaro:asyncio-current-task-native-impl
Dec 22, 2022
Merged
gh-100344: Provide C implementation for asyncio.current_task #100345
kumaraditya303
merged 11 commits into
python:main
from
itamaro:asyncio-current-task-native-impl
Dec 22, 2022
Commits on Dec 19, 2022
-
pythongh-100344: Provide C implementation for asyncio.current_task
Implementing it in C makes it about 4x-6x faster Microbenchmark: ``` # bench.py import time import timeit import asyncio ITERS: int = 10**6 NANO: int = 10**9 NANO_PER_ITER: float = NANO / ITERS async def main(): # avoid load attr noise py_current_task = asyncio.tasks._py_current_task c_current_task = asyncio.tasks._c_current_task asyncio.current_task() # warmup py_current_task() # warmup c_current_task() # warmup print( "current_task: {}ns".format(timeit.timeit(py_current_task, number=ITERS, timer=time.process_time) * NANO_PER_ITER) ) print( "current_task: {}ns".format(timeit.timeit(c_current_task, number=ITERS, timer=time.process_time) * NANO_PER_ITER) ) asyncio.run(main()) ``` a few runs on MacBook Pro 2.4 GHz 8-Core Intel Core i9 64 GB 2667 MHz DDR4: debug build: ``` ~/work/pyexe/main-dbg ⌚ 9:57:34 $ ./python.exe bench.py [py] current_task: 606.234ns [c] current_task: 104.47699999999993ns ~/work/pyexe/main-dbg ⌚ 9:57:59 $ ./python.exe bench.py [py] current_task: 631.856ns [c] current_task: 110.22500000000002ns ~/work/pyexe/main-dbg ⌚ 9:58:08 $ ./python.exe bench.py [py] current_task: 637.746ns [c] current_task: 105.03899999999999ns ~/work/pyexe/main-dbg ⌚ 9:58:16 $ ./python.exe bench.py [py] current_task: 621.3169999999999ns [c] current_task: 103.01300000000002ns ``` opt build: ``` ~/work/pyexe/main-opt ⌚ 10:33:17 $ ./python.exe bench.py [py] current_task: 128.743ns [c] current_task: 31.997999999999998ns ~/work/pyexe/main-opt ⌚ 10:33:24 $ ./python.exe bench.py [py] current_task: 126.388ns [c] current_task: 32.64599999999998ns ~/work/pyexe/main-opt ⌚ 10:33:26 $ ./python.exe bench.py [py] current_task: 137.053ns [c] current_task: 32.066999999999986ns ~/work/pyexe/main-opt ⌚ 10:33:28 $ ./python.exe bench.py [py] current_task: 131.17800000000003ns [c] current_task: 32.06600000000001ns ```
Configuration menu - View commit details
-
Copy full SHA for 76cbbc6 - Browse repository at this point
Copy the full SHA 76cbbc6View commit details
Commits on Dec 20, 2022
-
Configuration menu - View commit details
-
Copy full SHA for c7af32b - Browse repository at this point
Copy the full SHA c7af32bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5f33beb - Browse repository at this point
Copy the full SHA 5f33bebView commit details -
Optimize also the common case of the Python implementation of asyncio…
….current_task for ~40% speedup
Configuration menu - View commit details
-
Copy full SHA for 37072a1 - Browse repository at this point
Copy the full SHA 37072a1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5a8a8fd - Browse repository at this point
Copy the full SHA 5a8a8fdView commit details
Commits on Dec 21, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 8f0f80a - Browse repository at this point
Copy the full SHA 8f0f80aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 04bf985 - Browse repository at this point
Copy the full SHA 04bf985View commit details -
Configuration menu - View commit details
-
Copy full SHA for 637dfa7 - Browse repository at this point
Copy the full SHA 637dfa7View commit details -
Configuration menu - View commit details
-
Copy full SHA for c96db2c - Browse repository at this point
Copy the full SHA c96db2cView commit details
Commits on Dec 22, 2022
-
Configuration menu - View commit details
-
Copy full SHA for bdeb553 - Browse repository at this point
Copy the full SHA bdeb553View commit details -
Configuration menu - View commit details
-
Copy full SHA for 391db59 - Browse repository at this point
Copy the full SHA 391db59View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.