[erlang-questions] message copying overhead atoms vs binaries

Richard O'Keefe <>
Tue Jan 11 00:13:03 CET 2011

On 10/01/2011, at 11:56 PM, Paolo Negri wrote:

> Dear list,
> I'm trying to understand what approach of building values contained in
> messages to pass across processes would be more efficient (in terms of
> memory and cpu) and if the difference is significant.
> I could build my message values in two ways
> a) [{color, red}, {shape, circle}]
> b) [{color, <<"red">>}, {shape, <<"circle">>}]

Atoms do not need to be copied.
Large binaries are not copied, but small ones are.
From the Efficiency Guide:
  "The run-time system can represent binaries up to 64 bytes as heap binaries.
   They will always be copied when sent in a messages,"

> The actual lists are longer and can vary in length between 5 to 10 elements.
> The processes will exchange thousands of these messages each second
> and this is the reason why I'm asking this question.

Does the order of the pairs in a list matter?
I'm guessing that it doesn't.
If so, the information in
	[{colour,red}, {shape,circle}]
could equally well be held as
	{{colour,shape}, {red,circle}}
and then one wonders how many different properties there are and
how many combinations of properties and whether there might be some
way to exploit commonality between groups of property names.

But build it first and get it working and then measure it before
doing anything tricky.

More information about the erlang-questions mailing list