[erlang-questions] Deforesting tuple updates

Thomas Lindgren thomasl_erlang@REDACTED
Thu Feb 22 12:14:47 CET 2007

--- Bjorn Gustavsson <bjorn@REDACTED> wrote:

> Joel Reymont <joelr1@REDACTED> writes:
> > I remember that the update is performed
> destructively when the tuple  
> > is indexed with an integer or something like that.
> I would like to  
> > change this to generally use destructive tuple
> updates.
> > 
> Do you also plan to implement a write barrier in the
> garbage collector
> at the same time? If not, you are likely to get some
> nasty emulator crashes.

For those not into the GC lingo, write barriers are
needed because destructive updates can introduce
pointers from the old generation to the new one; these
must be traced along with all other roots when a minor
collection occurs, or the old generation will point to
garbage. A write barrier registers the old->new
pointer with the GC.

(The following assumes a classic, unshared heaps

An alternate option would be to introduce a
per-process flag to tell the system that all future
collections FOR THIS PROCESS must be major, in effect
using non-generational copying GC locally.

Since there is suddenly just one generation, there is
no need for a write barrier. The flag can be set when
a destructive update occurs, or even at process spawn
time. (The latter would be unsafe if the flag was not
set and destructive updates still used.)

The advantage with this approach is that it's fairly
straightforward to implement. Whether it's a good idea
depends on the program, of course. The cost of GC may
eat the gains, basically.


Yahoo! Music Unlimited
Access over 1 million songs.

More information about the erlang-questions mailing list