Use of --optimize

Hello everybody. I have used Elm for about one year and now I’m migrating to 0.19. By the way, I find elm fascinating.

I am a bit confused about the use of the --optimize flag. I am using the Buttons example from elm-lang for this test. If “making” with --debug flag I get a debug.html file with size 107.597 bytes. Applying --optimize flag to elm make I get a production.html file with size 106.343 bytes.

I expected a more important reduction in size due to removal of non-used code. Is this normal or is just that I’m doing something wrong?

Thanks a lot in advance!!.

We haven’t converted our projects to 0.19 yet, but my guess is that the new version of the compiler automatically performs certain optimizations on simple programs. 107 bytes is really small, so my guess this is already quite optimized. I think you’ll see a bigger benefit of the --optimize flag when compiling a larger program (e.g. try compiling the elm-spa-example).

It is normal but you are not seeing the full benefits. You should minimize and gzip the final JS in order to evaluate. You can use elm-minify tool if you want quick minification without having to bother with the options of uglifyjs.

In the counter example, it goes from 9.04kb to about 6.39kb which is a 30% saving. The elm-spa-example savings is about 12%.

In any case, the non-used code is no longer put in the output so, --optimize does not help with that.

What --optimize does is record field renaming.

Running elm by itself produces JavaScript code that is relatively readable. So it has a bunch of whitespace and long function names.

When you run it through the minification process described in you will crush all that out of the file.

Then I think you’ll see more of the difference it makes. I was seeing reductions in the 5% to 10% range after the (compile => minify => gzip) process but I’m not sure what you’ll get on really small programs.

Ah, ok. That’s pretty clear now. I will keep testing.

Thanks a lot.

And congratulations for the work on elm!

Just to close the question and complete the information for the future, these are the results compiling elm-spa-example, as @christian suggested. The .min.js is the result of applying elm-minify to the corresponding .js file.

compiling with --debug: js: 508.743 bytes, .min.js: 148.620 bytes
compiling without options: js: 384.660 bytes, .min.js: 107.987 bytes
compiling with --optimize: js: 370.448 bytes, .min.js: 92.915 bytes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.