[New-bugs-announce] [issue32357] Optimize asyncio.iscoroutine() for non-native coroutines
Yury Selivanov
report at bugs.python.org
Mon Dec 18 00:33:40 EST 2017
New submission from Yury Selivanov <yselivanov at gmail.com>:
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.
----------
components: asyncio
messages: 308515
nosy: asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Optimize asyncio.iscoroutine() for non-native coroutines
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32357>
_______________________________________
More information about the New-bugs-announce
mailing list