Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is dart2js code faster than javascript?

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.

like image 697
hkk Avatar asked Jan 05 '14 03:01

hkk


People also ask

What is dart2js?

The dart2js compiler provides hints and warnings for improving your Dart code. Also see dart analyze , which performs further analysis.

Does flutter use Javascript?

Flutter JS plugin. A Javascript engine to use with flutter. Now it is using QuickJS on Android through Dart ffi and JavascriptCore on IOS also through dart-ffi. The Javascript runtimes runs synchronously through the dart ffi.


1 Answers

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.

like image 161
Pixel Elephant Avatar answered Sep 29 '22 05:09

Pixel Elephant