Optimisation in Elm

187 views
Skip to first unread message

Ana Borovac

unread,
Apr 22, 2017, 3:19:08 PM4/22/17
to Elm Discuss
Hi,

I have some theoretical questions:

- why is Elm so fast? is there some kind of tail-recursion behind or is this just the part that JavaScript does?
- how is the storage mastered (garbage collection)?
- does commands (Cmd) influence on pureness of Elm?

Thank you so much for your help!

Ana

Peter Damoc

unread,
Apr 23, 2017, 3:34:14 AM4/23/17
to Elm Discuss
Hi Ana, 

1. Elm is fast because it use a very fast implementation of a virtual dom. 
2. Elm compiler outputs JavaScript so all the low level memory concerns are handled by the JavaScript VM, not by Elm
3. No, Cmds do not influence the purity of Elm. If a function returns Cmds, it will always return the same Cmds. Executing those Cmds might lead to different results BUT that's a different concern. 


--
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 elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

Marek Fajkus

unread,
Apr 25, 2017, 11:08:56 AM4/25/17
to Elm Discuss
Hello Ana!

Since no one have commented more on this thread for some time I'll add some addition points to Peter's answer myself.

First of all I think that you might misunderstand what tail recursion is but that's OK. I encourage you to look for some nice explanation on internet. I saw many folks misunderstand this over time and have wrote post on this topic myself. Anyway I can't tell that my post is good resource. I'm pretty sure you'll be able to find explanation you'll like since there are plenty of them.

Recursion thing aside I think Peter was right I'll just put it in my own words. Elm compiles to javascript that is fast. Javascript VMs are pretty complicated machines and even though they push really hard to make execution performant there are certain limits to that. Some things are hard to optimize to make them run fast. Elm simply produces javascript that makes it easy for browser to run rather then for human to read.

In addition to fast js virtual DOM implementation is also highly optimized for Elm's own needs so if you're building anything with elm-lang/html benefit from this for free too as well.

Marek
Reply all
Reply to author
Forward
0 new messages