Source [Announcing Dart 2.2: Faster native code, support for set literals]Today (February 26, 2019) we are announcing the release of the Dart 2.2 SDK update for Dart 2, which offers improved performance of
ahead-of-time (AOT) code and support for Set literals.

Increase Dart performance for development on Flutter
We continue our work to make
AOT-compiled code , like Flutter applications, even faster. In Dart 2.1,
we reduced the cost of type checking, significantly reducing the cost of type checking for both compiled AOT code and for code executed on a virtual machine with JIT (just-in-time) compilation.
')
In Dart 2.2, we focused on the performance of the AOT-compiled code, improving performance
by 11-16% on micro-benchmarks (by increasing the code size by ~ 1%). This improvement is the result of working over several quarters in order to reduce the costs of static calls. Our optimized AOT code can now call the requested object directly using a PC call (that is, using a
Program counter ). Before that, we had to search several times in the pool of objects to determine the required address. These optimizations are especially useful when the code contains many constructors and static method calls, such as the Flutter user interface code, which contains many widgets.
Set literals support in Dart 2.2
The main Dart library (dart: core) contains several collection classes:
Maps ,
Lists , and
Sets . Maps are sets of key-value pairs. Lists are ordered sequences of values, each of which can be accessed using an index and which can occur several times. Sets are unordered collections of values in which each value can occur only once and where you can effectively check if there is a value in the collection.
Dart collections are usually initialized by compile-time constants, and Dart offers a convenient syntax for writing this initialization. In the Dart List, you can initialize as follows:
const List<String> releases = ['Dart 2.0', 'Dart 2.1', 'Dart 2.2'];
Previously, Dart supported literal syntax only for List and Map, so the initialization of Set was cumbersome, since we had to initialize through a list:
Set<String> currencies = Set.of(['EUR', 'USD', 'JPY']);
This code is not just inconvenient and inefficient; the lack of support for literals does not allow creating an immutable Set at compile time. With the addition of support for Set literals in Dart 2.2, initialize the set and make it immutable using the convenient new syntax:
const Set<String> currencies = {'EUR', 'USD', 'JPY'};
Real examples of using Set literals with the Flutter command can be found
here . For more in-depth questions, we suggest that you familiarize yourself with the
updated Dart 2.2 language tour .
Delivering Innovation with Dart 2 Common Front-End (CFE)
Dart offers several of its implementations: the Dart VM used by Flutter, the dart2js compiler and the Dart dev compiler (dartdevc), all use the Common Front-End compiler. Dart Common Front End, or CFE, Parsit Dart code, performs type inference and translates Dart to an intermediate intermediate language, which the back end compilers accept as input.
Set literals are an example of a language construct that we were able to quickly implement thanks to CFE. The code for parsing the Set literals and performing type inference was implemented once with CFE for all implementations. In addition, we created a transient implementation that could be used by back end compilers at the initial stage. In the intermediate implementation, the modified version of the specified Set literals was translated into an equivalent form during the compilation:
Set<String> currencies = Set<String>()..add('EUR')..add('USD')..add('JPY');
The intermediate implementation of constant Set literals is different in that they cannot be assembled gradually in parts. Instead, we implemented it in terms of the private immutable Set class, which wraps an immutable Map, where the elements of the Set are Map keys:
const Set<String> currencies = _UnmodifiableSet<String>({'EUR': null, 'USD': null, 'JPY': null});
The immutable Set class implements methods in the Set interface, delegating them to an internal Map.
In general, we were able to implement Set literals initially as a function of CFE exclusively. The back end could immediately use the CFE implementation, and implement its own support later. This allowed back end compilers to postpone their support until the performance aspects of this function are better understood.
Dart 2.2 Specification
Dart 2 was such a significant update of Dart that it took us some time to update the
official language specification to fit all the changes we made. We have finally completed this work, and the specification has been updated to Dart 2.2. We also moved the language specification to a
new repository and added continuous integration to ensure that the specification is continuously updated in PDF format as future versions of the Dart language evolve. Both 2.2 and future Dart 2.x specifications are available
on the Dart specification page .
How to install Dart 2.2
Dart SDK 2.2 is available on the Dart homepage from today. If you are a Flutter developer, Dart 2.2 is already included. (Note: the current Flutter master and dev channels will report Dart 2.2 on the flutter doctor console command. The
current stable version of Flutter 1.2 will output Dart 2.1.2; this version has the same capabilities as Dart 2.2).
That's all for now. We hope you enjoy Dart 2.2!
Thank you so much for the help in translating
PsyHaSTe