Dart-to-JS compilation with Frog
Posted by David Chandler on November 2, 2011
I’ve been playing a bit with frog, the new Dart compiler written in Dart. Although it does not yet have all the capabilities of dartc, I’m seeing very nice improvements in compilation speed and the size of the resulting JS. Here’s some data for the sunflower and spirodraw samples:
- dartc: 109,612 bytes
- frog: 12,131 bytes
- dartc: 121,799 bytes
- frog: 24,320 bytes
The dartc results were obtained by running “dartc –optimize sample.dart”. The unoptimized JS is much larger.
> cd dart > ./tools/build.py --arch=ia32 -m release > cd frog > mkdir bin > ln -s ~/code/bleeding_edge/dart/xcodebuild/Release_ia32/dart_bin bin/dart_bin > ./frog.py --js_out=frogsh -- frog.dart > export PATH=$PATH:$PWD
Then I compiled the sunflower sample with frog:
> cd ../client/samples/sunflower > frogsh --compile-only --out=sunflower.js Sunflower.dart
Because the samples are designed to be compiled with htmlconverter.py, I also had to modify the script tag in sunflower.html to reference sunflower.js instead of Sunflower.dart (and removed type=”application/dart”).
Frog runs about 10x faster than dartc –optimize on the command line! This is comparable to dartc performance in the editor, which has the advantage of a warm JVM (frog, on the other hand, runs in the Dart VM). The dramatic difference in code size is likely because dartc had not yet implemented dead code elimination. And, unlike dartc, frog does not support incremental compilation so was able to take an entirely different approach. Also, frog is not finished, so there may be gotchas that appears as more corner cases are implemented. But for the moment, it looks very promising.