You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mypyc] Speed up native-to-native calls using await (#19398)
When calling a native async function using `await`, e.g. `await foo()`,
avoid raising `StopIteration` to pass the return value, since this is
expensive. Instead, pass an extra `PyObject **` argument to the
generator helper method and use that to return the return value. This is
mostly helpful when there are many calls using await that don't block
(e.g. there is a fast path that is usually taken that doesn't block).
When awaiting from non-compiled code, the slow path is still taken.
This builds on top of #19376.
This PR makes this microbenchmark about 3x faster, which is about the
ideal scenario for this optimization:
```
import asyncio
from time import time
async def inc(x: int) -> int:
return x + 1
async def bench(n: int) -> int:
x = 0
for i in range(n):
x = await inc(x)
return x
asyncio.run(bench(1000))
t0 = time()
asyncio.run(bench(1000 * 1000 * 200))
print(time() - t0)
```
0 commit comments