Erlang / Erlang Advanced Interview questions
Why is copying a large list between processes more expensive than copying a large binary?
A large binary (over 64 bytes) is stored off the process heap and reference-counted, so sending it in a message copies only a small pointer-sized reference — the actual byte data never moves. A list, by contrast, is a chain of individually heap-allocated cons cells with no such off-heap, reference-counted representation.
flowchart LR
subgraph Binary send
A1[Large binary off-heap] --> A2[Message copies a small reference]
end
subgraph List send
B1[List of cons cells on sender heap] --> B2[Every cell deep-copied into receiver heap]
end
When a list is sent in a message, the entire structure — every cons cell and every element — is deep-copied into the receiving process's heap, since processes share no memory and lists have no built-in sharing mechanism the way large binaries do. For data that's genuinely large and needs to move between many processes repeatedly, converting it to a binary (or storing it in ETS and passing a key/reference instead) is the standard way to sidestep this cost.
More Related questions...