Hacker News new | ask | show | jobs
by munificent 5093 days ago
The JS output that gets generated from a Dart program isn't just "dart_size * multiplier", it's "dart_size * multiplier + constant". So, when you see a tiny Dart program being compiled to a large amount of JS, that doesn't mean a large Dart program will compile to a huge amount of JS, it just means that the constant is dwarfing the multiplier.

The constant is coming from the runtime library (or, more accurately, the portions of the runtime library that your program uses). That's relatively fixed so as your Dart program gets larger, the overhead of that becomes relatively smaller. The actual code-size multiplier when going from Dart -> JavaScript is actually fairly small and getting smaller over time.

In some cases, we may actually compile Dart code to less JavaScript code because of things like dead code elimination and constant folding.

JavaScript code size is something that we consider a core metric for dart2js and we're constantly working to reduce it.

1 comments

Of course. I'm just a little concerned about how easy it is to inflate a program's size in Dart by including another core library.
That's true of every language, though, isn't it? If you use libraries, your app gets bigger.
I suppose so, I guess I'm too used to dynamic, interpreted languages that don't need to include the standard library in the output.