Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

One example is function inlining. If you need a code fragment called repeatedly you would refactor it out in a function/method. Dart2js often does the opposite. Method calls often get replaced with the code fragment contained by the called function/method which is called inlining. If you would do this manually this would lead to unmaintainable code.

I think many of the optimizations go in that direction. Writing the code that way would just be unreadable and thus unmaintainable. This doesn't mean it's sloppy.

There is a great presentation by Vyacheslav Egorov from the dart team where he explains in detail some of the optimizations including in lining..

http://www.infoq.com/presentations/dart-compiler

Summary Vyacheslav Egorov details how some of Dart's language features affected the design of a new JIT Dart compiler and how the V8 JavaScript engine influenced the overall design.

There is an interesting video by Seth Ladd and Kasper Lund. Kasper is involved in creating the Dart2js compiler and gives some code examples on how the compiler optimizes the Javascript code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top