[erlang-questions] learner's questions -- tuples, CEAN & jungerl
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Mon Apr 25 13:48:05 CEST 2011
On Mon, Apr 25, 2011 at 11:16, Icarus Alive <icarus.alive@REDACTED> wrote:
> 1. Found the following usage of tuple --
> { person, { name, joe }, { age, 42 } }
> Now when one has millions on such tuples, which are held in-memory,
> isn't the memory footprint of the application at-least 3 x 8-byte
> extranuous thanks to the 3 atoms (person, name, age), playing "field names"
> ? Is this a concern for anyone ? Is there are more efficient storage ?
It is actually far worse than 3 * 8 bytes as the representation is
boxed everywhere. So each of the tuples are also taking up memory.
There are some ways to limit the memory usage though:
a) Use records. If we have a record #person { name = joe, age = 42},
the internal representation is {person, joe, 42} which avoids a lot of
the tupling overhead.
b) Use the halfword emulator. The process-local representation would
in that case be much better.
c) If you store millions of these tuples, chances are you want to use
ETS for it. ETS takes a "compressed" option which trades speed for
space.
d) If you have rather rare access to the data, you can store them in a
binary format which take up less space.
Is it a concern? In some cases yes, but note that buying more memory
is a relatively cheap thing and that you have the above options to
counter it. My main concern is that the internal representation of
this, heavily boxed as it is, costs memory lookups - which then cost
execution speed compared to an unboxed representation. My concern
would be with the cache, not the total memory use.
--
J.
More information about the erlang-questions
mailing list