Skip to main content


Showing posts from March, 2013

Why dart2js produces faster JavaScript code from Dart

The dart2js compiler, which converts Dart to JavaScript, now produces smaller and faster code thanks to its global type inferencer. By analyzing the entire program, the compiler can eliminate bailouts and redundant checks, resulting in code that runs faster on modern JavaScript engines.

As evidenced by the graph below, the performance of the code generated by dart2js (the purple line) now slightly outperforms the original hand-written benchmark code (the gold line). The Dart VM, which natively runs Dart code, is the top line. High is better in this benchmark (Dart code, JavaScript code).

Type inferencing helps performance

Nicolas Geoffray, engineer on dart2js, has been working on the beginnings of the global type inferencer. In a recent interview (video) he showed examples of the original Dart code, the previously generated JavaScript code, and the new more optimized JavaScript code.

Code gets smaller, faster

For reference, here is a snippet of raw Dart code from the original benchmark:

An Important New Article on Working with Streams in Dart

Read Getting Your Feet Wet with Streams, the latest article at and learn about Streams in Dart.

How do you model values that vary over continuous time? Or deal with events which occur at finite points in time? In the Javascript world, the answer often involves using Functional Reactive Programming (FRP), with frameworks like RxJs, bacon.js and Flapjax providing elegant approaches to traditional event-driven programming. 

In Dart, Streams provide a consistent interface for working with repeating events. Streams are everywhere in Dart! 

In an important new article, Chris Buckett details ways in which you can subscribe to (and unsubscribe from) a Stream. He shows how to transform, validate and consume Stream data, and handle errors using a StreamSubscription.  This article demystifies the subject of Streams: read it if you want to know more about this important topic.

Your feedback really counts. Please join the conversation at the Dart mailing list, and ask questions at Stac…

Notes from the March 18 Dart Language Design Meeting

Once again, the always-helpful Bob Nystrom fills us in on the language design discussions taking place amongst Dart engineers. Here are his notes from the March 18 language meeting:
Lars: I like the "implements dynamic" thing. Gilad: Me too, it's like a get out of jail free card. Kasper: That means the type behaves like dynamic in all contexts? Even for is checks and checked mode checks? Gilad: If you assign something to it, it goes through normal rules. But if you assign it to something, works like dynamic. It could go both ways. Lars: The real solution would be to do it dynamically. Like you have noSuchMethod, you could have isSubtype on ClassMirror that returns a boolean. You could implement that to do what you want. Gilad: That's complicated to implement. Lars: Let's talk about the first solution with Ivan and Kasper. Kasper: That means it will be a subtype of all types. If a class claims it implements dynamic and List, should you get warnings if you …

Significant Dart Editor Release Brings Back String Plus Operator

Dart Editor has a new build. This is a significant release with a long list of breaking changes. You are urged to update your Dart code accordingly. 
Due to popular demand, the Dart team brought back the plus operator for string concatenation. That change has now landed in the Editor. Before this release, using + to concatenate strings produced this

Now, you can use + for concatenation. The concat() method has been deprecated:

There are numerous other changes in the core libraries, the dart:html library, and the dart:io library. 
Eric Clayberg fills us in on the details of this release:

A new Dart Editor build is available at Changes include: New analyzer available via experimental preference.
(work in progress, all features not enabled yet).Package root preferences removed in favor of --package-root cmd line option.Reduced heap usage by ~25%.Fixed a memory leak which could eventually consume 10% of the heap. Breaking Change List: Wide-ranging changes:All HTML c…

Irrduino: A Sprinkler System Built Using Arduino, Android, Google App Engine, Python, and Dart

Developers frequently ask me if Dart is ready for the real world. Well, of course, that depends on the application. Check out this short video in which Joe Fernandez and I not only show that Dart can be used in the real world, we also show that it can be used to take the tedium out of watering your lawn!

The Dart code for Lawnville was originally written in January of 2012, a mere three months after Dart was launched as a "technology preview". That was six months before Dart's M1 release, so it's been updated a few times along the way. However, the code really hasn't fundamentally changed that much since the beginning.

Perhaps the most interesting piece of code is the use of a Queue (from the dart:collection library) to schedule watering tasks. You can click on different parts of the lawn, and the droid will fly over and water each section for a short amount of time: _actionQueue = new Queue(); ... _actionQueue.add({'action': 'water', &#…

Dart VM Uses More CPU Features for Faster Performance

The Dart VM, a new virtual machine that runs Dart code, can now take advantage of SIMD instruction sets found in common CPUs. This means that Dart apps, when running in the Dart VM, can perform significantly faster for some algorithms. Code written with the new SIMD APIs still compiles to JavaScript, but won't see the same speed boost.

SIMD stands for Single Instruction Multiple Data, and is a set of CPU instructions for computing multiple results in parallel. The Dart SIMD APIs allow you to add, subtract, multiply, and divide four numbers at the same time. SIMD is widely used in games, 3D graphics applications, and more.

John McCutchan, Developer Programs Engineer on Dart, recently landed the changes with help from the Dart VM team. Watch John's talk from SFHTML5, and learn about his background optimizing console games, his journey to the web, and his quest to help web apps use all the CPU. The slides are also available.

New Article on Futures and Error Handling in Dart

Read the latest article at and learn about handing errors and exceptions when working with Futures.

Have you wondered how to implement the asynchronous equivalent of a try-catch? Or how errors actually get propagated when working with Futures? Or how you can prevent synchronous errors from leaking out of asynchronous code?  Then this article is for you.  

The article focuses entirely on error handling when working with Futures, explains how to handle errors that are emitted asynchronously, and points out a few gotchas that you should watch out for.  

Your feedback really counts. Please join the conversation at the Dart mailing list, and ask questions at Stack Overflow.

Photo credit:

New Dart Editor Release WIth Substantial Performance Improvement

Dart Editor has a new build. Daniel Rubel fills us in on the details:
A new Dart Editor build is available at Changes include:
Fixed a notable Editor performance issue related to Pub and symlinks. Breaking Change List:
Deprecated List.addLast. Use List.add instead.dart:indexed_db - Remainder of APIs have been converted over to Futures (this was a continuation of work from the conversions done in M3). *** Note that as a result this version does not include support for developing Chrome Applications. If you're using that feature, you should stick with the M3 release for now. ***

And as always, view the changelog for the full list of changes, and to get started with the Editor, see ourtutorial.
(Photo credit:

Notes from Feb 25th Language Meeting: Function Type Annotations, Optional Parameters and Exported Types

The invaluable Bob Nystrom fills us in on the language design discussions taking place amongst Dart engineers. Here are his notes from the February 25 language meeting:

Here's my notes from last week's meeting. I'll have this week's meeting notes out later this week:
function type annotations
Kasper noticed (or maybe someone noticed and brought it to his attention) that there is a place in Dart where seemingly innocuous type annotations do have a runtime effect. Given implicit closurization and is-checks with function types, you can:
1. Store a reference to a method in a variable. 2. Do an is check on that variable against some function type.
For that is check to perform correctly, it means we have to keep track of the methods type annotations at runtime.
The team discussed a bit about whether or not they want to make any changes around this, but didn't come to any conclusions.
optional parameters
We're entering a mode where changing the language gets increasingly hard…

Bootstrap Widgets Ported to Web Components with Dart Web UI

The wildly successful Bootstrap project, which helps web developers build responsive designs for web apps, has been ported to Dart's Web UI library. This means the dynamic widgets like accordion, carousel, tabs, and more, are reborn as actual web components. The Dart Widgets library has all the code, and you can easily install it from pub.

With real encapsulation, you can now use custom components that contain the structure, style, and behavior of the widget. For example, instead of using div elements with special classes and requiring another script to make it all work, you can simply use <x-accordion> which contains everything you need.

Here is an example:

    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse">Item 1</a>
    <p>Item 1 content - Lorem ipsum</p>
    <div class="ac…

New Dart Editor Build With More Libraries Moving To Using Streams and Futures

Dart Editor has a new build. Eric Clayberg fills us in on the details:

A new Dart Editor build is available at Changes include:
Cleanup for => onClick.listen changes.New application wizards updated for library changes.Bug fix for debugging Dartium launches on Windows machines using IPv6. Breaking Change List:
dart2js: temporarily remove --disable-unsafe-eval ***dart:htmlWeb SQL APIs have moved into dart:web_sql, Database was renamed to SqlDatabaseGeolocation API has been cleaned up w/ futures & streams.dart:ioVersion 2 of the dart:io library moving to using streams and futures extensively for all async operations instead for registration of callbacks.libraries:BiDirectionalIterator -> BidirectionalIterator *** Note that as a result this version does not support for developing Chrome Applications. If you're using that feature, you should stick with the M3 release for now. ***
And as always,view the changelog for the full list of changes, a…