|
|
|
|
|
by eseidel
504 days ago
|
|
I don't have a full answer for you, but I know a little. I've hacked on the Dart compiler some, but my relationship with Dart has mostly been as a creator of Flutter and briefly Eng Dir for the Dart project. Dart has multiple layers where it does tree shaking. The first one is when building the "dill" (dart intermediate language) file, which is essentially the "front-end" processing step of the compiler which takes .dart files and does amount of processing. At that step things like entire unused libraries and classes are removed I believe. When compiling to an ahead of time compiled binary (e.g. for releasing to iOS or Android) Dart does additional steps where it collects a set of roots and walks from those roots to related objects in the graph and discards all the rest. Not unlike a garbage collection. There are several passes of this for different parts of the compile, including as Dart is even writing the binary it will drop things like class names for unused classes (but keep their id in the snapshot so as not to re-number all the other classes). I have no experience with tree shaking in the dart2js compiler, but there are experts on Discord who might be able to answer:
https://github.com/flutter/flutter/blob/master/docs/contribu... What exactly all this means as a dev using Dart, I don't know. In general I just assume the tree shaking works and ignore it. :) The Dart tech lead has done some writings, but none seem to cover the exact details of treeshaking:
https://mrale.ph/dartvm/
https://github.com/dart-lang/sdk/blob/main/runtime/docs/READ... |
|