[erlang-questions] Strange optimization result

Bjorn Gustavsson <>
Sun Oct 21 11:48:14 CEST 2007


"Bob Ippolito" <> writes:

> In my experience using tuples for this purpose, it seems like in many
> or most cases tuples are instantiated from scratch every function call
> even though they're constant in the bytecode. You might just be
> assuming some optimization that Erlang doesn't actually do. This is
> the sort of thing that the hybrid model might fix, but as far as I
> know the only data structures that are on a global heap is large
> binaries, not tuples of any kind or size. I'm mostly just guessing
> though, because I have not read any of the Erlang VM's source (and
> it's great that I haven't had to!).

Correct for all releases up to and including R11B-5.

> You may have better luck restructuring your code in such a way that
> this can't happen, either by generating a function that is the
> equivalent of element(N, Tuple), e.g. a function with 256 clauses, or
> by keeping the tuple in the state of a process (maybe several
> processes) so that it doesn't get continuously allocated and
> deallocated.

That is good advice in general (up to and including all R11B releases),
but in this case I don't think that a constant tuple was used (i.e. the
tuple is already part of the state of a process).

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list