[elm-discuss] Re: Dead code elimination and the future of elm-runtime.js

2016-09-14 Thread Dave Thomas
Does Elm only include the parts you use in import statements or does the 
whole lot get included?

e.g. If I do:

import Html.Events exposing (onClick, onWithOptions)


Are only those parts included, or the whole shebang?

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


[elm-discuss] Re: Dead code elimination and the future of elm-runtime.js

2016-09-12 Thread OvermindDL1
>From my experience my elm app freshly compiled ends up at 2369KB, after 
closure, uglifyjs, etc... it ends up at 1145KB, then when gzipped it ends 
up at 338KB.  This is still pretty large considering the old react version 
of some of the components I replaced were less that 400KB pre-shrinking 
total (using react.min.js admittedly, never used the non-min react library) 
and much smaller after shrinking and gzipping.

For an example let's take 
[Bucklescript](https://bloomberg.github.io/bucklescript/), which adds a 
javascript back-end for the stock OCaml compiler, I.E. normal OCaml input, 
OCaml-compiler-optimized output to javascript, which includes DCE (Dead 
Code Elimination), inlining, and more, and they can compile the OCaml 
compiler (which is written in OCaml) to javascript, and have done so on 
their [Try 
Bucklescript](https://bloomberg.github.io/bucklescript/js-demo/index.html) 
page, where you can see it does directly convert `print_endline "Hello 
World!"` into `console.log("Hello World!");`, and as you import modules it 
optimizes what is used and not used and makes for very tight programs 
(while using OCaml-style normal FFI for integrating with javascript 
type-safe).

I would actually be quite curious in Elm taking a similar approach, build 
on top of an already well defined and strongly typed language instead of 
inventing a new language.  Elm is not the language but rather the style in 
my point of view.

(Honestly a dream browser language would be either OCaml or Haskell with an 
Elm-like library for interfacing, probably OCaml over Haskell.)

Segway aside, no, the closure compiler still does not shrink Elm very well 
even in mid-late 2016.

On Saturday, September 10, 2016 at 11:19:52 AM UTC-6, Brian Slesinsky wrote:
>
> Delegating to Closure is smart but the combination still needs to be 
> tested to really claim code size is solved. Writing code to allow tree 
> shaking isn't an entirely natural thing - new dependencies can happen 
> easily unless you have testing to tell you that code size has regressed.

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


[elm-discuss] Re: Dead code elimination and the future of elm-runtime.js

2016-09-10 Thread Brian Slesinsky
Delegating to Closure is smart but the combination still needs to be tested to 
really claim code size is solved. Writing code to allow tree shaking isn't an 
entirely natural thing - new dependencies can happen easily unless you have 
testing to tell you that code size has regressed.

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


[elm-discuss] Re: Dead code elimination and the future of elm-runtime.js

2016-09-10 Thread Robin Heggelund Hansen
First of all, I agree with all your main points. The size and scope of the 
runtime should not be dictated by the number of bytes it takes up. Also, 
the compiler does have more flexibility if it was all in JS.

However. As long as the target language is JS, I don't think DCE should be 
a priority, as we already have minifiers that provide this service for us. 
This also means that there is no reason to include a 'prod' or 'dev' mode 
to the compiler (at least not for this) as a 'prod' mode is simply adding a 
minifier step to your build configuration.

The elm compiler already outputs JS in a way that makes it very simple to 
remove dead code, and to minify well. The only 'problem' with the current 
way of things, is that the elm-runtime is written by hand, and thus not 
written in such a way that makes it easy to minify well and remove dead 
code. Re-writing more of the elm-runtime in elm should mitigate this 
further. In fact, I believe Elm already beats other languages like 
ClojureScript quite well in size, even though CLJS uses google closure for 
minification. The main advantage cljs has over Elm, is that cljs' runtime 
is written in cljs.

I also don't believe that elm-html should be a part of the standard 
library. While it might makes sense today, it makes less sense in the 
distant feature when someone has come up with a new, revolutionary and 
soon-to-become de-facto HTML library. It also wouldn't make sense if Elm 
ever becomes a backend or scripting language. It should be noted however, 
that my interpretation of what a standard library is, is a library that 
provides functions you would likely use in any app, and which are unlikely 
to do better any other way. The current standard library is, IMHO, fine the 
way it is when it comes to scope, while there are certain functions I would 
love to add to certain modules (like List.find). You're interpretation may 
be different. In any case, there is no reason to discuss the size and scope 
of the standard library here, I just thought I would voice my opinion that 
just because we have DCE, that doesn't mean should be uncritical with what 
we put in the standard library.

I would also like to point out that while optimizing for Google Closure is 
a good thing (tm), it should not come at the cost of hampering other 
minifiers like UglifyJS. UglifyJS already removes all dead code (except 
dead code in native code) quite well in my applications, and I would love 
for that to still be a thing in the future without swapping out Uglify with 
a Java application.

So yeah, my 2 cents essentially boils down to:
1) Move more runtime code from native to pure elm.
2) Explore a way to make native code as easy to minify/DCE as compiled Elm 
code.
3) Should the Elm compiler ever support another target in the future, spend 
resources on DCE.

torsdag 16. oktober 2014 16.12.46 UTC+2 skrev Laszlo Pandy følgende:
>
> Currently elm-runtime.js works like any JavaScript library: you include it 
> with your page and your generated Elm code use the exposed functions. In 
> fact you could even use it from hand-written JS code. But a language 
> runtime is not the same thing as a JS library.
>
> Recently many people have brought up two issues:
> - should elm-html be in the standard library?
> - why is elm-runtime.js so big?
>
> And here are two stories which indicate which direction Elm should be 
> heading in:
> 1. Since Haxe started, they were always concerned about compiled JS size. 
> They believed that JS devs wouldn't switch to Haxe if a hello world was 10K 
> of JS. So they kept the standard modules small. There was a class String 
> with a few functions, and StringTools[1] with many more. StringTools would 
> not be included if you didn't import it.
>
> Later on, Haxe implemented function-level dead code elimination. After 
> that it didn't matter how big String was. All the parts you didn't use 
> would be deleted from your output. Now StringTools is just API baggage that 
> shouldn't exist.
>
> [1] http://api.haxe.org/StringTools.html
>
> 2. Just like Elm's runtime is written in JS, Go's runtime is written in C. 
> But how there is a big project rewrite much of it in Go[2] to take 
> advantage of the compiler's stack layouts. But even if we are talking about 
> Elm and JS, there would be many advantages to having most of the runtime 
> written in Elm:
> - inlining, and other optimizations
> - function-level dead code elimination
> - less code maintenance (ie. if Elm changes its data structures)
>
> [2] 
> http://dave.cheney.net/2014/09/01/gos-runtime-c-to-go-rewrite-by-the-numbers
>
> What we see is:
> - dead code elimination decouples the runtime size from the API design. 
> This is a good thing
> - the runtime should be a collection of functions, not a self-contained 
> library to enable dead code elimination
> - the compiler has more flexibility if more functions are in Elm instead 
> of JS
>
> The direction Elm should be heading in is to have no separate 

[elm-discuss] Re: Dead code elimination and the future of elm-runtime.js

2016-09-09 Thread Devin Rhode
Because elm is purely functional, and because of this I would expect closure 
compiler run on advanced mode to remove just about every single unused 
function. I think it's good shared infrastructure. It really all comes down to 
extensibility and performance. Presumably building dead code removal into elm 
will speed things up a bit. Target es6 and we could also get tree shaking with 
rollup.js (iirc).

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