
Ken Manheimer wrote:
Hokay. I *think* i have this, and i have a question to followup.
...
In any case, one big unknown for me is the expense of continuations. Just how expensive is squirreling away the future, anyway? (:-)
The future costs at most to create *one* extra frame with a copy of the original frame's local stack. By keeping the references to all the other frames which were intact, the real cost is of course bigger, since we keep the whole frame path from this one up to the topmost frame alive. As soon as we drop the handle, everything winds up and vanishes. I also changed the frame refcounting to guarantee exactly that behavior. (before, unwinding was explicitly done).
If we're deep in a call stack, seems like there can be a lot of lexical-bindings baggage, plus whatever i-don't-know-how-big-it-is control logic there is/was/will be pending. Does the size of these things (continuations) vary extremely, and is the variation anticipatable? I'm used to some surprises about the depth to which some call or other may go, i don't expect as much uncertainty about my objects - and it seems like continuations directly transform the call depth/complexity into data size/complexity... ??
Really, no concern necessary. The state is not saved at all (despite one frame), it is just not dropped. :-) Example: You have some application running, in a nesting level of, say, four function calls. This makes four frames. The bottom function now decides to spawn 10 coroutines in a loop and puts them into an array. Your array now holds 10 continuations, where each one is just one frame, which points back to your frame. Now assume, you are running one of the coroutines/generators/whatever, and this one calls another function "bottom", just to have some scenario. Looking from "bottom", there is just a usual frame chain, now 4+1 frames long. To shorten this: The whole story is nothing more than a tree, where exactly one leaf is active at any time, and its view of the call chain is always linear. Continuation jumps are possible to every other frame in the tree. It now only depends of keeping references to the leaf which you just left or not. If the jump removes the left reference to your current frame, then the according chain will ripple away up to the next branch point. If you held a reference, as you will do with a coroutine to resume it, this chain stays as a possible jump target. for-me-it's-a-little-like-Tarzan-ly y'rs - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net 10553 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home