This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines
Type: performance Stage: resolved
Components: asyncio Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, yselivanov
Priority: normal Keywords: patch

Created on 2017-12-18 05:33 by yselivanov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bench.py yselivanov, 2017-12-18 17:24
Pull Requests
URL Status Linked Edit
PR 4915 merged yselivanov, 2017-12-18 05:37
PR 4989 merged yselivanov, 2017-12-23 16:44
PR 4990 merged asvetlov, 2017-12-23 16:55
Messages (4)
msg308515 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-12-18 05:33
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.
msg308631 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-12-19 12:18
New changeset a9d7e552c72b6e9515e76a1dd4b247da86da23de by Yury Selivanov in branch 'master':
bpo-32357: Optimize asyncio.iscoroutine() for non-native coroutines (#4915)
https://github.com/python/cpython/commit/a9d7e552c72b6e9515e76a1dd4b247da86da23de
msg308960 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-12-23 17:44
New changeset 558aa30f7971e087c4a00b1f49cc2ef3195c01ca by Yury Selivanov in branch 'master':
bpo-32357: Fix tests in refleak mode (#4989)
https://github.com/python/cpython/commit/558aa30f7971e087c4a00b1f49cc2ef3195c01ca
msg308967 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-12-23 20:06
New changeset 0f47fa2c89a6b9a04969219dfb0c3801c611e3ca by Yury Selivanov (Andrew Svetlov) in branch 'master':
bpo-32357: Use PySet_GET_SIZE macro in _is_coroutine() from _asynciomodule.c  (#4990)
https://github.com/python/cpython/commit/0f47fa2c89a6b9a04969219dfb0c3801c611e3ca
History
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76538
2017-12-23 20:06:48yselivanovsetmessages: + msg308967
2017-12-23 17:44:32yselivanovsetmessages: + msg308960
2017-12-23 16:55:19asvetlovsetpull_requests: + pull_request4878
2017-12-23 16:44:11yselivanovsetpull_requests: + pull_request4877
2017-12-19 12:19:04yselivanovsetstatus: open -> closed
type: performance
resolution: fixed
stage: patch review -> resolved
2017-12-19 12:18:47yselivanovsetmessages: + msg308631
2017-12-18 17:24:15yselivanovsetfiles: + bench.py
2017-12-18 05:37:46yselivanovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4809
2017-12-18 05:33:56yselivanovsettitle: Optimize asyncio.iscoroutine() for non-native coroutines -> Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines
2017-12-18 05:33:40yselivanovcreate