-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Snapshots
The Dart VM has long supported script snapshots that allow a Dart programmer to package up an application into a single file and reduce startup time.
$ dart --snapshot=hello.dart.snapshot hello.dart
$ dart hello.dart.snapshot arguments-for-use
Hello, world!
These snapshots contain tokenized sources, but lack parsed classes and functions and lack compiled code. This makes them fairly small and portable between CPU architectures. But it also means the Dart VM must still parse and compile all the classes and functions that are used in each run, which can be a substanial portion of run time for large programs that process a small input.
Starting in 1.21, the Dart VM also supports application snapshots, which include all the parsed classes and compiled code generated during a training run of a program.
$ dart --snapshot=hello.dart.snapshot --snapshot-kind=app-jit hello.dart arguments-for-training
Hello, world!
$ dart hello.dart.snapshot arguments-for-use
Hello, world!
When running from an application snapshot, the Dart VM will not need to parse or compile classes and functions that were already used during the training run, so it spends more time running the user's code.
These snapshots are CPU architecture specific, so a snapshot created by an x64 VM cannot run on an IA32 VM or vice versa. Also, because different code is generated in production mode and checked mode, an app snapshot created in production mode cannot be run in checked mode or vice versa.
Important
The wiki has moved to https://github.com/dart-lang/sdk/tree/main/docs; please don't edit the pages here.