23 ms·
Well, from that I gather that Dart transpiles to a huge lump of mostly useless code. It'd be nice to see a non-trivial script written in those languages run thr
by thomasfoster96 11y ago
Well, from that I gather that Dart transpiles to a huge lump of mostly useless code. It'd be nice to see a non-trivial script written in those languages run through uglify or the closure compiler to see how well they can be simplified.
- cwyers 11y agoHoly wow. Typescript: 15 lines Haxe: 18 lines Coffeescript: 26 lines JSX: 228 lines Dart: 791 lines
- munificent 11y ago> I gather that Dart transpiles to a huge lump of mostly useless code. It transpiles your code to a small lump of useful code. It also includes a runtime library which takes up a chunk of space. That ends up being a large fraction of the overall result when the application in question is "hello, world!", but in a real-world app, it's a relatively small piece of the pie. I'll also note that the Gist is from 2012. Dart is twice as old today as it was when that Gist was published. Here's what the output looks like today [1]. We have two compilers right now: dart2js is designed to produce output that runs as fast as possible and is as small as possible. You can think of it as "-O3". Optimize all the things at the expense of readability. The dart2js output on the simple example is 170 lines, or 5K of JS (before gzip). Still kind of big, but like I said, most of that is runtime library that amortizes better in large programs. dev_compiler, or "ddc" is for producing human-readable, debuggable output. It's like "gcc -g". No optimizations or minifications, fast compile times, maximum readability. Its output for this is 29 lines. This does not include the runtime library, since it compiles that to separate (also readable) files. The output uses ES6 and looks like: dart_library.library('simple', null, /* Imports */[ "dart_runtime/dart", 'dart/core' ], /* Lazy imports */[ ], function(exports, dart, core) { 'use strict'; let dartx = dart.dartx; class Simple extends core.Object { Simple(name) { this.name = name; } greet(who) { return `Greetings ${who}, I'm ${this.name}!`; } } dart.setSignature(Simple, { constructors: () => ({Simple: [Simple, [core.String]]}), methods: () => ({greet: [dart.dynamic, [dart.dynamic]]}) }); function main() { let s = new Simple('Flyn'); core.print(s.greet('Program')); } dart.fn(main); // Exports: exports.Simple = Simple; exports.main = main; }); //# sourceMappingURL=simple.js.map Pretty readable, I think, especially given how young ddc is. The team is still hard at work on it. [1]: https://gist.github.com/munificent/bde42b3d02c563fb4a9c https://gist.github.com/munificent/bde42b3d02c563fb4a9c
- stewbrew 11y agodart2js is designed to produce output that runs as fast as possible and is as small as possible. Speaking of small: What's the size of the dart_runtime/dart and dart/core that seemingly always gets imported?
- thomasfoster96 11y agoStill, that dart code looks a lot more complicated than it needs to be. While progress is obviously being made, it doesn't exactly give me confidence in using dart as a compile-to-JS language if it's going to have an overhead because of the addition of a runtime library.