| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
We were somewhat worried about the performance of creating a dict with kwargs and then unpacking it, but it seems pretty similar if not faster: It's a bit slower in the case where we have a name and a factory, which is a bit odd, but most of the time you'd be using a Loop subclass not a factory if you cared about this level of performance. import pyperf
runner = pyperf.Runner()
runner.timeit(
name="create a task with a name",
stmt="loop.create_task(coro(), name='hello')",
setup=["import asyncio; loop = asyncio.EventLoop()", "async def coro(): pass"],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task without a name",
stmt="loop.create_task(coro())",
setup=["import asyncio; loop = asyncio.EventLoop()", "async def coro(): pass"],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task with a name and factory",
stmt="loop.create_task(coro(), name='hello')",
setup=[
"import asyncio; loop = asyncio.EventLoop()",
"def task_factory(loop, coro, **kwargs): return asyncio.Task(coro, loop=loop, **kwargs)",
"loop.set_task_factory(task_factory)",
"async def coro(): pass",
],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)
runner.timeit(
name="create a task without a name, with a factory",
stmt="loop.create_task(coro())",
setup=[
"import asyncio; loop = asyncio.EventLoop()",
"def task_factory(loop, coro, **kwargs): return asyncio.Task(coro, loop=loop, **kwargs)",
"loop.set_task_factory(task_factory)",
"async def coro(): pass",
],
teardown="loop.call_soon(loop.stop); loop.run_forever(); loop.close()",
)before: 6f167d7 ..................... create a task with a name: Mean +- std dev: 1.27 us +- 0.10 us ..................... create a task without a name: Mean +- std dev: 1.29 us +- 0.10 us ..................... create a task with a name and factory: Mean +- std dev: 1.28 us +- 0.10 us ..................... create a task without a name, with a factory: Mean +- std dev: 1.34 us +- 0.10 us after: 539d2e9 ..................... create a task with a name: Mean +- std dev: 1.25 us +- 0.09 us ..................... create a task without a name: Mean +- std dev: 1.22 us +- 0.10 us ..................... create a task with a name and factory: Mean +- std dev: 1.53 us +- 0.11 us ..................... create a task without a name, with a factory: Mean +- std dev: 1.32 us +- 0.10 us |
Sorry, something went wrong.
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
Thanks @graingert for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
|
Sorry, @graingert and @kumaraditya303, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker 38a99568763604ccec5d5027f0658100ad76876f 3.13 |
Sorry, something went wrong.
|
GH-130084 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
…onGH-128768) (cherry picked from commit 38a9956) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…#130084) * [3.13] gh-128308: pass `**kwargs` to asyncio task_factory (GH-128768) (cherry picked from commit 38a9956) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> --------- Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
why did we break the API spec in a patch release? This caused a sudden breakage for us |
Sorry, something went wrong.
…ry (pythonGH-128768) (python#130084)" This reverts commit 7b0543e.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.