New submission from Yury Selivanov: loop.call_soon is the central function of asyncio. Everything goes through it.
Current design of asyncio.loop.call_soon makes the following checks: 1. [debug mode] check that the loop is not closed 2. [debug mode] check that we are calling call_soon from the proper thread 3. [always] check that callback is not a coroutine or a coroutine function Check #3 is very expensive, because it uses an 'isinstance' check. Moreover, isinstance checks against an ABC, which makes the call even slower. Attached patch makes check #3 optional and run only in debug mode. This is a very safe patch to merge. This makes asyncio another 17% (sic!) faster. In fact it becomes as fast as curio for realistic streams benchmarks. ---------- assignee: yselivanov components: asyncio messages: 280002 nosy: asvetlov, gvanrossum, haypo, inada.naoki, ned.deily, yselivanov priority: normal severity: normal status: open title: asyncio: Optimize loop.call_soon versions: Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28600> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com