>
> The reason is that BuckleScript proves that Arrays are faster than 
> "string" tagged objects and I have tried benchmarking it myself.  In fact, 
> I have gone further and manually substituted the use of Arrays rather than 
> the string tagged objects in the generated Elm code to show that is the 
> reason.  The problem isn't so much the use of Array's versus 
> objects/records, but the string tags, which as the Elm JS output doesn't 
> preserve type information except by these tags, are continuously requiring 
> string processing to determine the type of object at run time.  Elimination 
> of these strings by using the type information the compiler already has 
> would greatly speed things even if objects are used, with the further 
> advantage of Arrays being that their indices are numeric for slightly less 
> processing (depending on the browser engine used).
> This becomes readily seen the more functional the code, with the use of 
> tuples (tagged objects), lots of records (tagged objects), lists (nested 
> tagged objects) and so on, and these passed as (essentially untyped) 
> arguments across functions.


This goes against my own benchmarks, where replacing current Elm code with 
arrays proved slower. Accessing an element on a record was faster than on 
an array. Did you try against more than just one browser?

It is possible to eliminate some of the string tags, but in most cases you 
will need some sort of tagging. ADTs for instance, which is the majority of 
cases using tags, does pattern matching on the tag because you cannot know 
at compile time what object you're dealing with. You need some sort of 
tagging here, and since strings are interned in javascript, equality 
checking on a string is a very fast operation. In my tests there were no 
difference between using numbers or strings as tags.

Records are not tagged. They're just normal js objects.
Tuple types only uses tags when determining size. And that is only done for 
comparisons and equality checks if I remember correctly.
Lists are linked lists, and so require some sort of tagging. The most 
efficient way would to use some sort of possible null reference instead of 
a string tag, but I doubt it makes much difference.

I also fail to understand what you mean by this: "... and these passed as 
(essentially untyped) arguments across functions."
To the javascript runtime, everything is untyped anyway.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to