Key observation: 99.9% of the time Futures and Tasks have only one callback.
Currently we have a list of callbacks in each Future/Task. We can avoid list object allocation if we add a field to store the first callback. This way we'll only need to ever allocate the list if a Future/Task has more than one done callbacks.
asyncio with the proposed patch applied shows that 3-6% better performance of an asyncio echo server implemented using asyncio.streams. This benchmark involves quite a bit of other Python code, so this improvement is actually quite significant.
The patch consists of:
first callback / callbacks list refactoring.
a free list implementation for Future.__await__ objects (which are created on almost all awaits in asyncio).
a big cleanup of the code, ensuring that Future/Task are always initialized properly.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: