This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How often are continuations created?


Hello,

I am thinking of implementing cheap continuations for my VM
by the following algorithm:

 1. Create many stack segments and a stack free list at startup.

 2. Each VM has a data stack, which keeps intermediate computations,
    and a control stack, where frames are allocated.

 3. When stack overflow is detected, a new stack is detached from
    the free list and connected to the current stack.

 4. When a continuation is captured, the current control stack is
    detached from the VM and passed to the continuation object.
    A new control stack from the free list is connected to the
    continuation stack.  The contents of the data stack are copied.

 5. When a continuation is reinstated, the current control stack
    is replaced by the continuation stack.  The data stack is also
    rewritten.

This algorithm is quite simple and must be efficient for both regular
procedure calls and continuation calls, as long as there are sufficient
stack segments on the free list.

The question is how often and how many continuations are created.
If thousands of continuations are created at once, the free list is
immediately exhausted and new stack segments must be allocated from
the heap, which is very expensive.  But if only a limited number of
continuations are created at once, there will be neither memory
allocation nor stack copying (except a few data stack copying).

Is this a good idea to implement?

Thanks,
Keisuke Nishida

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]