[erlang-questions] Updating Myths of Erlang Performance

Tony Rogvall tony@REDACTED
Sun Jun 5 17:55:25 CEST 2016

> On 5 jun 2016, at 07:46, Björn Gustavsson <bjorn@REDACTED> wrote:
> On Sat, Jun 4, 2016 at 10:33 PM, Tuncer Ayaz <tuncer.ayaz@REDACTED> wrote:
>> On 4 June 2016 at 08:13, Björn Gustavsson <bjorn@REDACTED> wrote:
>>> 2.1  Myth: Funs are Slow
>> What exactly? Calling a fun (object) or creating one? Isn't the time
>> to construct fun objects considerable enough that one shouldn't
>> do it in, say, a loop?
> That was not the point with the myth at all, and I thinks that proves
> that it is time the myth is retired.
> Funs were really slow before R6B, at least an order of magnitude
> slower than today. The virtual machines (neither JAM nor BEAM) had any
> native support for funs. The function modules_lambdas() in each module
> had a clause for each fun defined in the module. The fun terms
> themselves were represented as 5-tuple. When a fun was called, the
> tuple had to be matched to extract the module that defined the fun,
> the arguments had to be packed into a tuple, and modules_lambdas() had
> to be applied. (Tony might remember more details about the
> implementation.)

We liked sweet syntactic sugar a lot more back then. ;-)
But yes. It was more like a proof of concept.

Fun objects looked like {’fun’, Module, Index, Uniq, Free} where Index was a local function index,
Uniq a ’unique’ number and Free was the closure.

call to a function F(1,2,3) was transformed into apply(F, [1,2,3]) which in turn was
transformed into a call to apply_lambda(F, [1,2,3])

if F = fun(X,Y,Z) -> A+X+Y+Z+B end   ( A and B in closure )
then the function object F was transformed into something like {’fun’,mmm,1,1234,{A,B}}
so the call F(1,2,3) would then look like:

	F = {’fun’, mmm, 1, 1234, {A,B}},
	apply_lambda(F, [1,2,3])

the per module (mmm in this case) generated apply_lambda for F may have looked something like:


	apply_lambda({fun, mmm, Index, Uniq, Free}, Args) ->
		module_lambdas(I, Uniq, Args, Free);

So apply_lambda was just a dispatch for local and remote functions called from within a module.
And module_lambdas:

	module_lambdas(1, 1234, [X,Y,Z], {A,B}) ->
	other functions

But that was a loooooong time ago :-)


> /Björn
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160605/b92744d2/attachment.bin>

More information about the erlang-questions mailing list