Performance Zone is brought to you in partnership with:

Victor works on the Angular team at Google. He is interested in functional programming, the Web platform, and client-side applications. Being a language nerd he spends a lot of my time playing with Smalltalk, JS, Dart, Scala, Haskell, Clojure, Ruby, and Ioke. Victor is a DZone MVB and is not an employee of DZone and has posted 47 posts at DZone. You can read more from them at their website. View Full User Profile

Why Dart Comes with a Virtual Machine

04.18.2014
| 8146 views |
  • submit to reddit

Dart comes with a high-performance virtual machine. This controversial decision led to questions if it is going to break the Web. In this article I want to look at why we need this virtual machine, and how it can be added to Chrome without breaking the Web.

Server Side

One place where even the strongest opponents of Dart will not mind using the Dart VM is the server side. The Dart execution model is very similar to the one in Node.js. In addition, the Dart virtual machine is already much faster than V8, and also has a good concurrency story. All this makes it a good candidate for writing high-performance IO-intensive services.

During Development

When compiling a language with different semantics to JavaScript, there are a few options available:

  • The compiler is fast, but naive.
  • The compiler is advanced, but not as fast.

The Dart engineers picked the latter. The generated JavaScript code is fast and small, but the compilation process takes some time. Which is not a big deal when you compile your app before pushing it to production. It is an issue, however, when you are developing. Even if the compilation takes a second, it is a second too long. Having the Dart VM is crucial for providing the same interactive development experience we all love.

Browser

Embedding the VM into to browser gives you better performance and start-up time. I am not talking about marginal gains here. It is about twice as fast comparing to V8, and the start-up time for some apps can be speeded up by a factor of ten. Both are extremely important, especially on mobile devices.

The issue that rightfully concerns many programmers is how do we make sure Dart developers provide the compiled-to-js version of their programs. Only in this case their applications will work in all modern browsers.

How not to break the Web

One way to ship Chrome with the Dart VM, and make sure that Dart applications work in all modern browsers, is to request the JavaScript versions of the applications from time to time. So even if you use a browser with the Dart VM in it, you will get the JavaScript versions of Dart programs every tenth time. This will ensure that developers will provide the compiled-to-js versions of their programs. By the way, this strategy is not new. It was successfully used when the support of the SPDY protocol was added to Chrome.

Summing Up

Having a dedicated VM has a lot of benefits:

  1. The VM can be used on the server side.
  2. The VM can be used to speed up development process.
  3. The VM can be shipped to the browser to improve the startup time and the speed of applications, and it can be done without breaking the Web.
Published at DZone with permission of Victor Savkin, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)