5 ms·
Yesterday, I rewrote one of my JS modules into Dart, and it ended up being about 10 lines of code with only two modules imported. Then I compiled it to JS, and
by weareconvo 14y ago
Yesterday, I rewrote one of my JS modules into Dart, and it ended up being about 10 lines of code with only two modules imported. Then I compiled it to JS, and it was over 120k. I tried for about an hour to get that down to a reasonable size with Closure Compiler/Uglify, but the names were too wonky.
I'm sure that, given enough time, they'll solve these problems, but as for right now... it isn't ready for primetime. Not by a longshot.
- afsina 14y agoRelated: http://blog.sethladd.com/2013/03/i-shrunk-my-dart-to-js-code-by-11x-and.html http://blog.sethladd.com/2013/03/i-shrunk-my-dart-to-js-code...
- michaelwww 14y agoYou don't say if you used the 'dart2js --minify' setting, but Closure Compiler should do well. The --minify flag leaves alot more room for additional minification. You say you used two modules. The result really depends on the modules. For example, the Dart/JS interop module adds about 140K un-minified. Tree shaking is always on, so the 140K is after stripping unused code. I initially jumped into Dart because I was interested in doing packaged apps that run locally, so the size over the wire didn't concern me as much. I recently converted an ActionScript app to Dart and the post-minify Dart was around the same size as the compiled .swf file (for comparison, same functionality) Seth Ladd has a couple of posts about Tree Shaking and Minification if you're interested http://blog.sethladd.com/2013/01/minification-is-not-enough-you-need.html http://blog.sethladd.com/2013/01/minification-is-not-enough-... http://blog.sethladd.com/2013/03/i-shrunk-my-dart-to-js-code-by-11x-and.html http://blog.sethladd.com/2013/03/i-shrunk-my-dart-to-js-code...
- weareconvo 14y ago> You don't say if you used the 'dart2js --minify' setting I did. I'm no stranger to Closure Compiler, and even after fiddling around with ADVANCED_OPTIMIZATIONS for an hour, those ridiculous $variables persisted. What was even weirder was, just as a test, I imported a module I wasn't even using at all, and for some reason, Closure Compiler still refused to remove its code...
- michaelwww 14y agoJust for grins, I compiled the Dart app I'm working on now with --minify. It went from 530K to 240K. Then I cleared the --minify flag and used the Closure Compiler but it failed with errors. Not sure what is going on yet, but I don't think this is necessary or advisable -- I've never read of anyone using the Closure Compiler with Dart. Here is a sample few lines from --minify. It's fairly minimal. function I(){} init() var $=I.p var $$={}
- weareconvo 14y agoOkay, but um, why did minify not get rid of the module i wasn't even using?
- michaelwww 14y agoJust to be clear, here is what I did. Dart source -> dart2js -> JavaScript (530K) Dart source -> dart2js -> JavaScript (530K) -> Closure Compiler -> *error* Dart source -> dart2js --minify -> JavaScript (240K) If I import a module and don't use it, such as 'dart:utf', the resulting JavaScript output size does not go up. If I call a function in dart:utf the JavaScript size goes up. If I stop calling the function, the size goes down. If I create a function but don't call it, the size stays the same. If I call it, the size goes up. Everything seems to be working. They just release a new version a few days ago and I'm on the latest.
- kyrra 14y ago--minify is still being improved and is not complete yet. As well, you need to say what libs you included. If you import "HTML" it is basically like including jquery.
- weareconvo 14y agoRight, but the great thing about a compiled language like Dart is that it can detect at compile-time which modules aren't being used and then exclude those from the js output. Except, it doesn't seem to ever do that. EDIT: Well, technically, Dart is actually designed to be interpreted (or JIT compiled, or what have you) by the Dart VM, so calling it a "compiled language" was incorrect on my part. However, dart2js is a compiler, so, it should be doing compiler-y shit.
- kyrra 14y agoTree-shaking is the term for removal of uncalled functions. The minifier is still early on so expect it to get better with time.