How can Google's Dart get better performance? How can Google's Dart get better performance? dart dart

How can Google's Dart get better performance?


This thread is a must read for anyone interested in dynamic language just in time compilers:http://lambda-the-ultimate.org/node/3851

The participants of this thread are the creator of luajit, the pypy folks, Mozilla's javascript developers and many more. Pay special attention to Mike Pall's comments (he is the creator of luajit) and his opinions about javascript and python in particular.He says that language design affects performance. He gives importance to simplicity and orthogonality, while avoiding the crazy corner cases that plague javascript, for example.

Many different techiques and approaches are discussed there (tracing jits, method jits, interpreters, etc).Check it out!

Luis


The article is referring to the optimization difficulties that come from extremely dynamic languages such as JavaScript, plus prototypal inheritance.

In languages such as Ruby or JavaScript, the program structure can change at runtime. Classes can get a new method, functions can be eval()'ed into existence, and more. This makes it harder for runtimes to optimize their code, because the structure is never guaranteed to be set.

Prototypal inheritance is harder to optimize than more traditional class-based languages. I suspect this is because there are many years of research and implementation experience for class-based VMs.

Interestingly, V8 (Chrome's JavaScript engine) uses hidden classes as part of its optimization strategy. Of course, JS doesn't have classes, so object layout is more complicated in V8.

Object layout in V8 requires a minimum of 3 words in the header. In contrast, the Dart VM requires just 1 word in the header. The size and structure of a Dart object is known at compile time. This is very useful for VM designers.

Another example: in Dart, there are real lists (aka arrays). You can have a fixed length list, which is easier to optimize than JavaScript's not-really-arrays and always variable lengths.

Read more about compiling Dart (and JavaScript) to efficient code with this presentation: http://www.dartlang.org/slides/2013/04/compiling-dart-to-efficient-machine-code.pdf

Another performance dimension is start-up time. As web apps get more complex, the number of lines of code goes up. The design of JavaScript makes it harder to optimize startup, because parsing and loading the code also executes the code. In Dart, the language has been carefully designed to make it quick to parse. Dart does not execute code as it loads and parses the files.

This also means Dart VMs can cache a binary representation of the parsed files (known as a snapshot) for even quicker startup.


One example is tail call elimination (I'm sure some consider it required for high-performance functional programming). A feature request was put in for Google's V8 Javascript VM, but this was the response:

Tail call elimination isn't compatible with JavaScript as it is used in the real world.