[New-bugs-announce] [issue33505] Optimize asyncio.ensure_future by reordering if conditions

Jimmy Lai report at bugs.python.org
Mon May 14 16:45:32 EDT 2018


New submission from Jimmy Lai <yurinai at gmail.com>:

`ensure_future` converts the input as future if it's not already a future.
The condition is the following:

if futures.isfuture(coro_or_future):
    ...
elif coroutines.iscoroutine(coro_or_future):
    ...
elif inspect.isawaitable(coro_or_future):
    ...

In real world, `ensure_future` is mostly called by `run_until_complete` and gather with async function call (coroutine) as input.
We should check `iscoroutine` first to make it most efficient.

----------
components: asyncio
messages: 316572
nosy: asvetlov, jimmylai, yselivanov
priority: normal
severity: normal
status: open
title: Optimize asyncio.ensure_future by reordering if conditions
type: performance
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33505>
_______________________________________


More information about the New-bugs-announce mailing list