How is dart2js code faster than javascript?

Issue

I’m trying to better understand dart’s effect on performance. On the dart website, their benchmarks show that Dart code compiled to Javascript is faster than just Javascript. How is this possible?

Tracer Benchmarks

I understand how the Dart VM is faster than v8, but what I don’t get is how dart2js-generated javascript is faster than plain old javascript, when both are running in the same environment, v8.

Solution

dart2js is able to perform optimizations that would not normally be manually added in JavaScript code.

There is nothing particularly special about Dart being the source language in this case: any automated tool that generates JavaScript should be able to do this, for instance the GWT compiler (Java to JavaScript) does this as well. Of course, you can run automated tools on JavaScript source to generate better JavaScript as well, this is what the Closure compiler does.

Technically, you can manually achieve the same speed with handwritten JavaScript if you know all the tricks.

Answered By – Pixel Elephant

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *