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

Álvaro avalormaquedano@REDACTED
Wed Nov 28 17:29:23 CET 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121128/2a167096/attachment.htm>


More information about the erlang-questions mailing list