[erlang-questions] efficient way to make some resources available as precompiled beams

Benoit Chesneau bchesneau@REDACTED
Mon Aug 20 11:30:43 CEST 2018

Hi all,

I'm wondering what Is most efficient when you want to make some resource
available as precompiled beams.

Say for example, you have a a resource available as CSV and there is a need
for a lookup on this list based on one of column.

I am for now transforming this list in a list of matching functions
(lookup(X1) ->. V1; ... lookup(XN) -> VN.). Ie you have a CSV (simplified

    Key1; V1
    Key2; V2
    KeyN; VN

which is transformed in the following erlang file, later compiled:

    lookup(Key1) -> V1;
    lookup(Key2) -> V2;
    lookup(KeyN) -> VN.

But with the new optimisations in Erlang 20/21 sharing literals I am
wondering if it wouldn't be more efficient to use a maps there?

So the generated erlang file would be:

    -define(to_lookup_map, #{ Key1 => V1;
                                               Key2 => V2;
                                               KeyN => VN }).

     lookup(Key) -> maps:get(Key, ?to_lookup_map).

A maps would also have some benefit in compressing a little the info I

Thoughts?  Beside that maybe having that ressource in a memory mapped file
would be better? I believe that beams are fully loaded in RAM, aren't they?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180820/9196204b/attachment.htm>

More information about the erlang-questions mailing list