Skip to content

Can it be used to implement yield and await? #43

Answered by rossberg
oovm asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by oovm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants