[erlang-questions] Retrieving "semi-constant" data from a function versus Mnesia

Wed May 13 11:11:51 CEST 2015

> 2:
> In the current web-application project I work with (implemented on top of
> Yaws) I have the following type of function-call construct ( to achieve
> server-side method-dispatching )
> Variable_module_name:fixed_function_name(),
> According to the efficiency-guide of the Erlang-documentation this type of
> call-construct is more "expensive" (about six times) compare to a fully
> fixed name function-call.
> In what sense is it more expensive ?


> ....is it about the time-lag between
> the point when the VM catch/discovers this call-construct and the point
> when the functional content (the prepared sub-routines) actually can be
> executed ?

If you compile a little example using erlc +"'S'" and then poke
around in beam_emu.c, you'll see that the dynamic function call
takes a couple of C function calls to find the place to go.
One of them is or was erts_find_export_entry(module, function, arity),
surprise surprise, which looks the triple up in a hash table, so it's
fairly clear where the time is going.

Another approach would be to do something like this:
if module m exports fn, generate
    ' apply f'(X1, ..., Xn, m) -> m:f(X1, ..., Xn);
and translate a csll M:f(E1, ..., En) as
    ' apply f'(E1, ..., En, M).

Looking at ...:...(...) calls in an Erlang/OTP release,
I found
    17.5% ?MODULE:function  -- ?MODULE &c
    81.6%  module:function
     0.0%  module:Function  -- some but very few
     0.8%  Module:function
     0.0%  Module:Function  -- some but very few
These figures are a bit dodgy but wouldn't be too far wrong.
In any case they're static figures, not dynamic.

While I think this kind of call _could_ be faster, I suspect
that they are fast _enough_ given their rarity and the other
things going on in a program.

More information about the erlang-questions mailing list