[erlang-questions] pass-by-reference...

Richard Carlsson richardc@REDACTED
Sun Apr 15 19:37:29 CEST 2007

tsuraan wrote:
> Ok, that's probably what I was thinking of, then.  Why is message
> passing handled that way?  Isn't it basically a special case of
> function calling?  I understand that between processes on different
> computers you would want to copy data, but why can't it be shared when
> the processes are on the same machine?

Oh, it can. The problems are not with the sharing in itself, but
with creating a well-balanced memory management system that has
low overhead for garbage collection - and in particular, short
pauses (on average) for garbage collection.

The original (and still the default) runtime system uses strictly
separate heaps for each process, and always copies data when sending
messages. This is slower (but most messages are very small), and
since it duplicates data, some applications are written to explicitly
avoid sharing data the naive way, storing it in ETS tables instead.
The advantage is that most process heaps remain small, and that they
can be garbage collected without looking at any other process heap,
which means that you mostly have very short pauses. This system is
surprisingly hard to beat.

There was an experimental (now abandoned) runtime system with a
single shared heap, but it had problems with long pause times.
There have also been experiments with incremental, real-time
garbage collection, but that tends to have unacceptably high
overhead, even if it has very short pause times. (I think that
work is still being done in this area, though.)

There is now an experimental hybrid system that still has
separate heaps for each process, but also has a shared area
where messages are placed. With compiler assistance, the system
is able to create a large part of the message data directly
in the shared area; the remaining data is copied to the shared
area when it is sent. This system has shown some promise.

The main thing is: if you want to beat the current standard
runtime system implementation, you need to achieve *both* short
pause times and fast message passing (more sharing), not just
either of them.

More material can be found here:



More information about the erlang-questions mailing list