Elm is fast.
Can we make it faster?
Turns out, yes!
We’ve put together elm-optimize-level-2
, which is a CLI tool that adjusts the javascript that Elm generates to make it faster. Once installed, you can just call elm-optimize-level-2
instead of elm-make --optimize
.
This speedup should essentially be “free” in that you don’t need to do anything to your code, and your post-minification asset sizes should actually be ever so slightly smaller than before.
Big Note - We’ve tested the code on all of our benchmarks and I’ve verified that things seem to be working as expected on Blissfully (our app is something like ~160k lines-of-code Elm program).
However, beware, elm-optimize-level-2
is adjusting the javascript itself! This project does have the potential to break you Elm project in very un-Elm ways.
But also let us know how it goes!
Science and Speed
There are two sides to this project.
The first is that this is actually a science project to gather data on what JS forms would be beneficial for Elm. It’s a lab where we can try things, collect notes, and verify ideas with actual numbers.
The repo already includes:
- Documentation on interesting transformations
-
A browser-automated benchmarking suite, which allows us to run
elm-explorations/benchmark
benchmarks from a number of realworld Elm projects and collect cross-browser numbers.
The second part of this project is to take the transformations that are the most useful and provide them as a tool you can use now.
The Team
Even though this is under my name on the repo, this has been a joint project with Simon Korzunov! I’m positive this project wouldn’t be nearly as comprehensive without him.
Also, my personal inspiration came from Robin Heggelund Hansen’s article on areas where the Elm Compiler’s output could be improved. Definitely check it out!
What sort of speedup are we talking about?
Good question!
Well, first, there needs to be a bit of a disclaimer.
Your numbers will likely vary depending on a lot of different factors.
You may not see any speedup at all depending on what you’re doing.
However, we do have some very encouraging/exciting results!
Here’s a small sample:
Html
Name | Transformtions | Browser | Ops/Second | % Change |
---|---|---|---|---|
create a 4 level nested html tree | safari | 34,899 | ||
create a 4 level nested html tree | final | safari | 39,631 | (+14%) |
create a 4 level nested html tree | firefox | 15,909 | ||
create a 4 level nested html tree | final | firefox | 22,361 | (+41%) |
create a 4 level nested html tree | chrome | 28,959 | ||
create a 4 level nested html tree | final | chrome | 72,753 | (+151%) |
Elm Markdown
Name | Transformtions | Browser | Ops/Second | % Change |
---|---|---|---|---|
dillonkearns/elm-markdown | safari | 2,428 | ||
dillonkearns/elm-markdown | final | safari | 3,196 | (+32%) |
dillonkearns/elm-markdown | firefox | 1,096 | ||
dillonkearns/elm-markdown | final | firefox | 2,194 | (+100%) |
dillonkearns/elm-markdown | chrome | 2,489 | ||
dillonkearns/elm-markdown | final | chrome | 3,572 | (+44%) |
Let us know if you try this out!
Happy to answer any questions. Hopefully everything works as intended and I’m not forgetting something
(Small note, the npm package was published incorrectly, but it now should be working.)