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.

Author v2m
Recipients v2m
Date 2020-10-19.19:38:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Content has introduced PyIter_Send as a common entrypoint for sending values however currently fast path that does not use StopIteration exception is only available for generators/coroutines. It would be quite nice if this machinery was extensible and other types (both internal and 3rd party) could opt-in into using exception-free way of returning values without needing to update the implementation of PyIter_Send. One way of solving this is adding a new slot with a signature that matches PyIter_Send. With it:
- it should be possible to implement this slot for coroutines/generators and remove  special casing for them  in PyIter_Send
- provide implementation for this slot for internal types (i.e. FutureIter in _asynciomodule.c) - results of this experiment can be found below
- enable external native extensions to provide efficient implementation of coroutines (i.e.  Cython could benefit from it)

Microbenchmark to demonstrate the difference of accessing the value of fulfiled Future without and with dedicated slot:
import asyncio
import time

N = 100000000

async def run():
    fut = asyncio.Future()

    t0 = time.time()
    for _ in range(N):
        await fut
    t1 = time.time()
    print(f"Time: {t1 - t0} s")
Time: 8.365560054779053 s - without the slot
Time: 5.799655914306641 s - with the  slot
Date User Action Args
2020-10-19 19:38:17v2msetrecipients: + v2m
2020-10-19 19:38:16v2msetmessageid: <>
2020-10-19 19:38:16v2mlinkissue42085 messages
2020-10-19 19:38:16v2mcreate