You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines #76538
asyncio.Task now uses asyncio.iscoroutine() to give a comprehensible error if a user creates a Task for a non-awaitable type.
The problem is that iscoroutine() is quite expensive for non-native coroutines (like the ones compiled with Cython), as it uses isinstance(obj, collections.abc.Coroutine) call. This makes 'loop.create_task(cython_coroutine)' 20% slower than 'loop.create_task(python_coroutine)'.
The PR adds a positive type cache to the iscoroutine() function and to the asyncio.Task C implementation. Both caches make 'loop.create_task()' equally fast for all kinds of coroutines.
changed the title [-]Optimize asyncio.iscoroutine() for non-native coroutines[/-][+]Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines[/+]on Dec 18, 2017
New changeset 0f47fa2 by Yury Selivanov (Andrew Svetlov) in branch 'master': bpo-32357: Use PySet_GET_SIZE macro in _is_coroutine() from _asynciomodule.c (bpo-4990) 0f47fa2
Activity
1st1 commentedon Dec 18, 2017
asyncio.Task now uses asyncio.iscoroutine() to give a comprehensible error if a user creates a Task for a non-awaitable type.
The problem is that iscoroutine() is quite expensive for non-native coroutines (like the ones compiled with Cython), as it uses
isinstance(obj, collections.abc.Coroutine)call. This makes 'loop.create_task(cython_coroutine)' 20% slower than 'loop.create_task(python_coroutine)'.The PR adds a positive type cache to the iscoroutine() function and to the asyncio.Task C implementation. Both caches make 'loop.create_task()' equally fast for all kinds of coroutines.
[-]Optimize asyncio.iscoroutine() for non-native coroutines[/-][+]Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines[/+]1st1 commentedon Dec 19, 2017
New changeset a9d7e55 by Yury Selivanov in branch 'master':
bpo-32357: Optimize asyncio.iscoroutine() for non-native coroutines (bpo-4915)
a9d7e55
1st1 commentedon Dec 23, 2017
New changeset 558aa30 by Yury Selivanov in branch 'master':
bpo-32357: Fix tests in refleak mode (bpo-4989)
558aa30
1st1 commentedon Dec 23, 2017
New changeset 0f47fa2 by Yury Selivanov (Andrew Svetlov) in branch 'master':
bpo-32357: Use PySet_GET_SIZE macro in _is_coroutine() from _asynciomodule.c (bpo-4990)
0f47fa2