[erlang-questions] refactoring a very large record

Matthew Sackman matthew@REDACTED
Thu Oct 20 17:25:28 CEST 2011

On Thu, Oct 20, 2011 at 05:19:36PM +0200, Jesper Louis Andersen wrote:
> Right, A record is a tuple. A tuple is a set of pointers to elements
> (or tagged integers). When you update an element, a new tuple gets
> written. This new tuple copies all pointers from the old one and
> updates the pointers for newly written elements. This is necessary due
> to persistence.

Please explain more about this. Why can analysis tell you how many live
pointers there are to the old record and thus inform the VM whether or
not it can do update-in-place?

> The number of pointer-words copied is proportional to
> the tuple size. You can avoid a lot of those copies by make the tuple
> more tree-structural as fewer words then has to be copied upon update.
> The trick is to find out what parts of the tuple belong together and
> then push those out in auxiliary subtuples.

Yes, but the downside to that is that sending large nested records
between processes is very expensive - flatter structures seem to be
easier, probably (guessing) due to contiguous memory. Horses for courses
and all that.


More information about the erlang-questions mailing list