Subject: Re: Stacks, lists, and the cost of consing (was Re: Tail recursion)
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/10/29
Newsgroups: comp.lang.lisp
Message-ID: <719i2g$1gb49@fido.engr.sgi.com>
Gareth McCaughan  <gjm11@dpmms.cam.ac.uk> wrote:
+---------------
| The reason why stack allocation is better when it's possible
| is that, actually, stack allocation is very very cheap. You
| just increment a pointer to do the allocation, and decrement
| it to deallocate.
+---------------

With a generational copying garbage collector, almost all allocations
are just a pointer bump too, and don't require deallocation at all.
The "nursery" or "ephemeral" area memory is just reclaimed (in toto)
at the next minor collection. That is, the small amount of still-live
data in the ephemeral area is scavenged (copied), and the allocation
pointer is reset to the beginning of the ephemeral area. With a properly-
sized ephemeral area (and assuming typical allocation patterns), the
cost of the minor collection may be as low *or lower* than the cost of
all those individual pointer decrementings in the stack case.

Note also that Baker's CPS/only-call-never-return/allocate-on-the-C-stack-
and-let-the-GC-longjmp is essentially the same method, but it (1) uses
the C stack pointer *as* the allocation pointer for the ephemeral area,
and (2) it *requires* the program be converted to CPS.

Some people [e.g., Appel] claim that you can get similar performance
with a separate ephemeral/generational GC, without forcing the CPS
conversion on the code.


-Rob

-----
Rob Warnock, 8L-855		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-964-0811
Mountain View, CA  94043	PP-ASEL-IA