-
I'm implementing a small language that compiles to wasm, and I'm wondering if this proposal would be helpful in implementing yield-based generators and await-based coroutines. If possible, does it have any advantages in terms of size and performance compared to state machine transformation or continuation pass style transformation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
These are some of the 'core' uses cases anticipated for 'core stack switching'. There are several approaches to SS being considered, but, for all of them, asynchronous programming are high on the list of anticipated applications. |
Beta Was this translation helpful? Give feedback.
-
The relative performance of stack switching vs a state machine transformation also is highly dependent on the concrete usage pattern. The state machine approach performs better as long as generators are shallow and consist of small functions with little state. But it is linear in the nesting depth of the intermediate call stack, i.e., the distance between generator loop and yield point. For example, a recursive generator (e.g., a tree traversal) performs much worse under the state machine approach than with direct stack switching, whose cost is roughly constant per yield. See e.g. Figure 9 in this paper, which measures C++ coroutines against a stack-switching mechanism across varying recursion depth. |
Beta Was this translation helpful? Give feedback.
The relative performance of stack switching vs a state machine transformation also is highly dependent on the concrete usage pattern. The state machine approach performs better as long as generators are shallow and consist of small functions with little state. But it is linear in the nesting depth of the intermediate call stack, i.e., the distance between generator loop and yield point. For example, a recursive generator (e.g., a tree traversal) performs much worse under the state machine approach than with direct stack switching, whose cost is roughly constant per yield. See e.g. Figure 9 in this paper, which measures C++ coroutines against a stack-switching mechanism across varying recu…