Hacker News new | ask | show | jobs
by callum85 4100 days ago
> the resulting JS is said to be more performant than raw JS.

This claim always bugged me. The output of dart2js is raw JS. Same with CoffeeScript (which makes a similar claim). So these claims are totally reliant on parameters that haven't been defined, ie. what constitutes "equivalent" handwritten code?

2 comments

Right, I hope people making this claim realize it's not possible in principle for Dart to always be faster.

I've always assumed claims like this are implying that average case code is written poorly and that's how It could be faster.

However as you point out we'd need all the assumptions made clear to believe such a claim.

it is up to every test to specify. I think they did explain what kind of hand written js they compared to and if I recall correctly the tests the dart team mentions is compared do js written by experienced js developers to solve the exact same problem. Of course there is a possibility that the hand written code could be further optimized but the comparison is still interesting.
What am I missing that makes this only a "possibility" rather than a certainty? For any Dart program found to be faster than a JS program, the JS program could be made equally fast by being equivalent to the Dart output, right?
By going through the dart compiler first they can do optimizations that you wouldn't do by hand. Google runs all their js through their Closure compiler for this (JS -> JS compiler) with a ton of optimizations turned on (constant folding, method inlining, deadcode elimination, replacing of multiline conditionals with ternary operator, etc, some of which I believe are in the open source version and possibly some proprietary).

In that case, they literally are writing JS and using a compiler to get JS that is faster than any normal handwritten JS would be. You could write your JS that way but it would be completely unreadable and unmaintainable.

Thank you for the clarification. I think we are saying the same thing.

In principle, it's always a certainty that JS can be written as performant as Dart, never just a possibility. The possibility part only comes in with respect how optimally the JS code is written.

The interesting part here is I think is how often does this happen? How often can significant improvements be made that would be impractical, or even unlikely for a developer to match?

I suspect that depends on your definition of significant. I suspect any legible code can always get a few percent speedup by doing things that would make it unreadable and unmaintainable.