[erlang-questions] Anonymous functions or callback module - Performance

Daniel Goertzen daniel.goertzen@REDACTED
Wed Nov 28 21:36:21 CET 2012


Take a look at http://www.erlang.org/doc/efficiency_guide/functions.htmlfor
the cost of various calls.

Now the document only talks about the relative cost of various calls.
 Perhaps call cost pales in comparison to the cost of executing your
functions.  Benchmarking is the only way to find out for sure if call cost
is relevant for you.


This code...

FList = [F1 = fun callback_module:fun_1/1 end... F1 = fun
callback_module:fun_3/1].

... has led me to another question for the mailing list:  Will these funs
automatically use a new version of loaded module or are they permanently
fixed to the old version?

Dan.


On Wed, Nov 28, 2012 at 10:29 AM, Álvaro <avalormaquedano@REDACTED> wrote:

> Hi Erlangers,
>
> I have a question regarding the pros and cons of using anonymous functions
> instead of functions stored in a callback module.
>
> Let me introduce my program:
>
> I need to handle lists of functions e.g.: FList = [F1,F2,F3] where I must
> then use them in the following way ( given some term X):
>
> Result1 = F1(X),
> [... some other computations]
> Result2 = F2(Result1),
> [... some other computations]
> Result3 = F3(Result2),
>
> Now, I am defining FList = F1...F3 as
> FList = [F1 = fun callback_module:fun_1/1 end... F1 = fun
> callback_module:fun_3/1].
>
> The problem is the following:
>
> If I recompile and load the code for the callback module (hot code
> swapping) the output of some functions (e.g. Result2 from F2) may not be
> suitable for consequent ones (e.g. F3), as these latter ones are using the
> updated version of the code.
>
> A possible solution can be defining the list of functions as:
> FList = [F1 = fun (X) -> X+1 end, ..., F3 = fun(X) -> X *2 end]
> (of course these functions do not invoke any code that could be hot
> swapped)
>
>
> My question is:
>
> Shall I expect a big decrease of the performance if I use the second
> alternative? The list of functions can be quite big (maybe few hundreds of
> functions).
>
> I must say that the callback module is always the same for the functions
> appearing in the same list of functions (so all these would be loaded if
> the module is loaded, right?).
>
>
>
> I hope I have made my problem clear.
> Any help will be much appreciated.
> Cheers,
> Álvaro
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121128/bbf5077a/attachment.htm>


More information about the erlang-questions mailing list