arctan y
arctan y

Reputation: 21

In dartlang, what are the differences between dill and kernel snapshot?

Considering -
The file encoding, The file size, Inner data structure, Startup time and etc.

And what is the main reason to choose dill file to start dart application? Which one has better startup time performance? And why?

Upvotes: 2

Views: 1901

Answers (2)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657348

https://mrale.ph/dartvm/ is a great summary from a long-time Dart language team member.

As I understand it dill files and kernel snapshot are the same thing. dill is just the name for the file extension used for Kernel (AoT snapshots)

Since Dart 2 VM no longer has the ability to directly execute Dart from raw source, instead VM expects to be given Kernel binaries (also called dill files) which contain serialized Kernel ASTs. snapshot

I assume what you actually want to know is the difference between AoT and JiT snapshots.

Initially snapshots did not include machine code, however this capability was later added when AOT compiler was developed. Motivation for developing AOT compiler and snapshots-with-code was to allow VM to be used on the platforms where JITing is impossible due to platform level restrictions.

Snapshots-with-code work almost in the same way as normal snapshots with a minor difference: they include a code section which unlike the rest of the snapshot does not require deserialization. This code section laid in way that allows it to directly become part of the heap after it was mapped into memory.

Startup time

AppJIT snapshots were introduced to reduce JIT warm up time for large Dart applications like dartanalyzer or dart2js. When these tools are used on small projects they spent as much time doing actual work as VM spends JIT compiling these apps.

So the main reason to use AOT is that JIT is not allowed (mainly iOS) or for short-lived commands where continual optimization based on code usage (hot-spot) would unlikely lead to any results.

For a discussion about the size see also https://github.com/dart-lang/sdk/issues/28655#issuecomment-428370886

Upvotes: 3

Ben Butterworth
Ben Butterworth

Reputation: 28552

Since you are wondering about size, startup time, etc.

  • For fastest launch + small size (but not portable): use AOT snapshot
  • For portability (includes dart runtime) + fast launch (but large): use Self-contained executables (exe)
  • For portability (excludes dart runtime) + smallest size (but slow): use Portable snapshots (kernel)

Size

I took a random dart program from the internet (a seemingly non functioning dart program, upgraded it to Dart 2.12/ sound null safety), and built all the outputs:

  • Original files (main.dart, calc.dart) 74B and 3.0K
  • exe (Self-contained executables) 4.9M
  • main.aot (AOT snapshot) 1.0M
  • main.dill (Kernel snapshot) 6.8K
  • The jit one didn't output any files, it just ran the program, even when I ran dart compile jit-snapshot main.dart -o calc.jit

Startup time

The start up time is documented at dart compile.

Although kernel snapshots have reduced startup time compared to Dart code, they can have much slower startup than architecture-specific AOT output formats.


Answering the title

.dill is the extension for portable snapshots (kernel). From Dart Compile docs:

Use the kernel subcommand to package up an app into a single, portable file that can be run on all operating systems and CPU architectures. A kernel snapshot contains a binary form of the abstract syntax tree (Kernel AST) for a Dart program.

Here’s an example of creating and running a kernel snapshot:

$ dart compile kernel bin/myapp.dart
Compiling bin/myapp.dart to kernel file bin/myapp.dill.
$ dart run bin/myapp.dill

Upvotes: 0

Related Questions