Arrays and tuple write (setelement) optimization

Robert Virding <>
Sat Jul 7 01:37:54 CEST 2001

Hakan Stenholm <> writes:
>So I'm wondering if someone has considered adding such a optimization to the
>erlang compiler/VM or are there any problems I forgot about ?

This has been in two different forms:

1. The first, from before ETS, was nukeable arrays.  The write
operation was destructive and returned a new reference to the array
while the old reference was "nuked".  This ensured that the
destructive operation preserved non-destructive semantics by
maintaining uniqueness at runtime.  A runtime version of uniqueness

2. The second, which exists in the current inplementation though not
reachable, are vectors.  The write operation is also destructive and
returns a new reference while the old reference is updated with enough
info so that it still looks the same as before.  It preserves
non-destructive semantics but prioritizes using the modified

One problem is that it is very sensitive to keeping old references
around, the update operations can become quite costly in both time and
space.  Björn tested my dict implementation, which tries to be smart
by heavily reusing tuples, and it apparently went slower with vectors.

The first is more efficient, but the second preserves Erlang semantics
for terms.

A datatype like this would be useful, I suppose it is just a matter of
deciding what you want.  Having both would a Bad Thing!


More information about the erlang-questions mailing list