[erlang-questions] Why are messages between processes copied?

Richard O'Keefe ok@REDACTED
Thu Feb 23 23:06:01 CET 2012

On 23/02/2012, at 9:46 PM, Masklinn wrote:
> Currently the content of the message is copied from one process heap
> to the next, in the case of local messages, correct?
> If the runtime knew the message (and its components) is not re-used
> after sending it, it could *move* the whole message from one heap to
> the next skipping the copy step (but needing to cooperate a bit with
> the GC I guess, in order to invalidate the local pointer in the
> origin process).

I am trying to understand how moving is different from copying.

>> Using escape analysis to determine if the whole message should be
>> copied or only a reference would require a rewrite of the GC from
>> copy-and-collect to something like mark and sweep.
> Not sure why.

Because if any part of a message is not copied,
that part is still in the original process's heap,
and even though it might have no references in the original
process, is still not garbage.  Indeed, the sending process
might die.

Before trying to get fancy, the big question is

If you have benchmarks showing that message copying is taking up
a substantial proportion of your system's time, then we have a
problem.  If all of the data in a message are actually *examined*
by the receiver, it is difficult to see how copying could be a
*huge* problem.

Another issue of course is the process synchronisation required
during a message send.  Using some kind of lock-free "add a node
to a queue" approach might well be more scalable than something
using per-process locks.  If, that is, there are processes that
more than a few other processes want to send messages to.

Benchmarks!  Numbers!  Real Engineering!

More information about the erlang-questions mailing list