Todays random walk of dartness has lead me to generating and executing snapshots.
What is a snapshot in terms of Dart? Serialized binary heaps. It has been said that snapshots can help apps startup 10X faster. dart2js is a working example of this in action, when you execute the dart2js compiler it is actually running from a snapshot file.
How can I currently generate them? (Might not be this way in the future) As of now you need to build from source so the gen_snapshot binary is built. gen_snapshot is the tool built from gen_snapshot.cc.
Running gen_snapshot --help we find the flags needed to generate a snapshot script.
1234567891011121314151617181920212223242526
~/dart_bleeding/dart/xcodebuild/ReleaseIA32
$ ./gen_snapshot --help
No snapshot output file specified.
Usage:
gen_snapshot [<vm-flags>][<options>]\{--script_snapshot=<out-file> | --snapshot=<out-file>}\[<dart-script-file>] Writes a snapshot of <dart-script-file> to <out-file>. If no
<dart-script-file> is passed, a generic snapshot of all the corelibs is
created. One of the following is required:
--script_snapshot=<file> Generates a script snapshot.
--snapshot=<file> Generates a complete snapshot. Uses the url
mapping specified on the command line to load
the libraries.
Supported options:
--package_root=<path>
Where to find packages, that is, "package:..." imports.
--url_mapping=<mapping>
Uses the URL mapping(s) specified on the command line to load the
libraries. For use only with --snapshot=.
The dart vm provides a flag that allows the vm to load the dart script from a snapshot.
12
--use_script_snapshot=<file_name>
executes Dart script present in the specified snapshot file
Combining all this together and using the benchmark_harness we can test out creating and running a dart application from a snapshot.