[erlang-questions] Why are messages between processes copied?
Thu Feb 23 00:05:26 CET 2012
On 23/02/2012, at 11:22 AM, H. Diedrich wrote:
> I had naively thought that Erlang would be sending process messages around profiting from the fact that data is immutable and NOT copying it. And really just send a 'pointer'.
> Why is that not so, it should be a huge gain from immutable data, especially with bigger data. You don't have to copy, knowing that your data is immutable.
Did you ever do metalwork at school?
They teach you: "see that bump in the metal? If you just bang that flat with a hammer, the
distortion will just pop up somewhere else. You have to smooth things out by tapping gently
all over the place, spreading the distortion out so it's not noticeable."
It's like that with computing costs. If you make one thing cheaper, you often make something
else more expensive. Messages should normally be *small*, so that they are cheap to copy (any
bulk data is normally a binary, and large binaries *are* shared between processes within a
node). Sharing a heap means that garbage collection is now a nasty lots-of-threads-interacting-
with-a-giant-mutable-data-structure problem, affecting *everything* all the time.
A shared heap has been tried for Erlang, and it will doubtless be tried again in the future.
More information about the erlang-questions