Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Google's Dart get better performance?

I've read the article about Google's upcoming DASH/DART language, which I found quite interesting.

One thing I stumbled upon is that they say they will remove the inherent performance problems of JavaScript. But what are these performance problems exactly? There aren't any examples in the text. This is all it says:

  • Performance -- Dash is designed with performance characteristics in mind, so that it is possible to create VMs that do not have the performance problems that all EcmaScript VMs must have.

Do you have any ideas about what those inherent performance problems are?

like image 649
Sune1987 Avatar asked Sep 25 '11 15:09

Sune1987


People also ask

Does Google own Dart?

Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications.

Is Dart weakly typed?

Q. Is Dart a statically typed language? Yes, Dart 2 is statically typed.

What language is Dart written in?

Dart was originally developed to be included within the Chrome browser, which is mostly C++ already. Chrome is very demanding by itself, as it is both multi-threaded and multi-process.

Who created Dart?

Approved as an Ecma standard (ECMA-408), Dart is a general purpose programming language which was created by Google. Its major use is in the creation applications for web, servers, mobiles and Internet of Things devices.


3 Answers

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

like image 117
user876508 Avatar answered Oct 30 '22 02:10

user876508


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.

like image 22
Seth Ladd Avatar answered Oct 30 '22 02:10

Seth Ladd


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.

like image 5
Dan Cecile Avatar answered Oct 30 '22 02:10

Dan Cecile