4 ms·
> "If a call to an async function is immediately awaited, we immediately execute the called function up to its first await. If the called function reaches a ret
by csmpltn 5y ago
> "If a call to an async function is immediately awaited, we immediately execute the called function up to its first await. If the called function reaches a return without needing to await, we will be able to return that value directly without ever even creating a coroutine object or deferring to the event loop. This is a significant (~5%) CPU optimization in our async-heavy workload."
Step 1: "Who needs Threads? Just async/await all the things!"
Step 2: Build complex logic to untangle your nonsensical use of async/await and force things to run synchronously in the backend without the user knowing. See? A 5% CPU optimization right there!
- toxik 5y agoAsynchronous execution is not a replacement for parallel execution. That is not the value proposition of asynchronous execution models.
- pcwalton 5y ago> Step 2: Build complex logic to untangle your nonsensical use of async/await and force things to run synchronously in the backend without the user knowing. See? A 5% CPU optimization right there! Addressing your snark, I assume this optimization is targeted at places where you have a single "await" expression in the source that might call different functions at runtime, only some of which need to await.
- _carljm 5y agoOr there are just different code paths in the called function (eg a “cache hit” code path and a “cache miss” one), and only some of the code paths need to await.
- nly 5y agoThis exact optimization has been implemented in C++ coroutines via the 'initial_suspend' coroutine traits hook. ...and those are stackless coroutines under AOT compiled conditions, so it only saves a malloc.