Previously constants were referenced via there relative binary offset, i.e. a constant reference saying 42 meant at byte offset 42 relative to the start of the constant table in the binary. This was done to be able to (on the VM side) read the needed constants lazily. It meant, though, that constants had to be stored in a map, mapping from the byte position to the constant. This change adds a level of indirection when needing the lazy reading, but lets the constant references reference the constant number instead so that a constant reference saying 42 means constant number 42, i.e. constants can be stored in a list instead of in a map. This is done on the dart side, but the VM still stores it in a map. The level of indirection is a tabel next to the constant table where each entry has constant size (4 bytes) from which one can read the relative byte offset into the constant table from the constant number, thus still being able to read needed constants lazily. This CL also cleans up a leftover where for instance double constants had their textual representation saved as a string in the string indexer (and thus the output dill) even though they were never referenced. File size changes: * Platform: increses 7,816 bytes. * Compile of dart2js (including platform): decreases 71,424 bytes. Speed changes: * Adding `UserTag`s to the code and looking at observatories cpu profile on a `pkg/kernel/test/binary_bench.dart --golem AstFromBinaryLazy` run of a compile of dart2js reading the constant table has gone from ~10% to ~5%. * Doing statistics on `pkg/kernel/test/binary_bench.dart --raw AstFromBinaryLazy` run of a compile of dart2js says -6.28169% +/- 4.97269%. * Golem runs has nothing above the noise level. It does say "AstFromBinaryLazy (Intel Xeon) -4.006% (0.4 noise)" and "AstFromBinaryEagerP50 (Intel Core i5) -8.929% (0.6 noise)" though. TEST=All tests running the VM tests this. Change-Id: I07ead457527a4477de803ee55ba742f5557413d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196925 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
Dart Kernel
Dart Kernel is a small high-level language derived from Dart. It is designed for use as an intermediate format for whole-program analysis and transformations, and to be consumed by codegen and execution backends.
The kernel language has an in-memory representation in Dart and can be serialized as binary or text.
Both the kernel language and its implementations are unstable and are under development.
This package contains the Dart part of the implementation and contains:
- A transformable IR for the kernel language
- Serialization of kernel code
Note: The APIs in this package are in an early state; developers should be careful about depending on this package. In particular, there is no semver contract for release versions of this package. Please depend directly on individual versions.
See ast.dart for the in-memory IR, or binary.md for a description of the binary format. For now, the textual format is very ad-hoc and cannot be parsed back in.