Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Dart VM still used?

Tags:

flutter

dart

I've been using dart/flutter for a few projects, and I'm really enjoying it.

I've read that when building a mobile app, dart builds a native app with native code. But I've also read that dart has its own VM for performance.

What I'm trying to understand is if that VM is what is used when you build a mobile app, or is it building other code that it compiles for the native app. And if its doing something else, what is the dart VM still used for?

like image 436
DragonFax Avatar asked Oct 26 '17 18:10

DragonFax


People also ask

Does Dart use a VM?

Dart's compiler technology lets you run code in different ways: Native platform: For apps targeting mobile and desktop devices, Dart includes both a Dart VM with just-in-time (JIT) compilation and an ahead-of-time (AOT) compiler for producing machine code.

Does Dart run on JVM?

Google's newest programming language can now be run on the JVM, thanks to the JDart project hosted on Google Code. Unveiled at the goto conference last week, the Dart language is seen by some to be suitable for Java developers who can't get into Javascript.

Does Flutter use Dart?

Flutter uses the Dart Language that was created by google also, to be honest i'm not a fan of strongly typed languages like C# or JAVA, but i don't know why Dart's way of writing code seems different. And i feel very comfortable writing it. Maybe because it's very simple to learn, and very straightforward.

Is Dart compiled to Java?

Dart is compiled to native machine code (ARM, Intel, ...) executable and bundled with some native platform code (Java, Kotlin, Objective-C/Swift) to interact with the native platform.


2 Answers

Short answer: yes, Dart VM is still being used when you build your mobile app.

Now longer answer: Dart VM has two different operation modes a JIT one and an AOT one.

In the JIT mode Dart VM is capable of dynamically loading Dart source, parsing it and compiling it to native machine code on the fly to execute it. This mode is used when you develop your app and provides features such as debugging, hot reload, etc.

In the AOT mode Dart VM does not support dynamic loading/parsing/compilation of Dart source code. It only supports loading and executing precompiled machine code. However even precompiled machine code still needs VM to execute, because VM provides runtime system which contains garbage collector, various native methods needed for dart:* libraries to function, runtime type information, dynamic method lookup, etc. This mode is used in your deployed app.

Where does precompiled machine code for the AOT mode comes from? This code is generated by (a special mode of the) VM from your Flutter application when you build your app in the release mode.

You can read more about how Dart VM executes Dart code here.

like image 114
Vyacheslav Egorov Avatar answered Sep 18 '22 18:09

Vyacheslav Egorov


When the Dart VM is used in release mode, it is not really a VM (virtual machine) in the traditional sense of a virtual computer processor implemented in software, which has its own machine language that is different from the hardware's machine language.

This is what causes the confusion in the original question. In release mode, the Dart VM is basically a runtime library (not much different than runtime libraries required by all high level languages).

like image 40
Wm Leler Avatar answered Sep 19 '22 18:09

Wm Leler