feat: experimental tree shaking support#1664
Conversation
|
Open question: where should tree shaking live? Expo has its own experimental tree shaking as a serializer plugin. It also has constraints that make adopting Metro-core tree shaking non-trivial: custom Should tree shaking live in Metro core as the source of truth with Expo eventually delegating to it, or should Metro close the door and fully delegate to Expo's implem? |
|
@bacarybruno: re
We don't currently intend to designate the current, experimental tree-shaking implementation in Expo's core to be stable. It's a proof of concept, and transferring the AST from the transformer to the serialiser, while being the path of least resistance, isn't what we intend to do. If Metro ships an implementation upstream, we're happy to adopt it and/or tweak as needed to fit it to the existing expectations we need it to comply to. The main assumption we had was that it'd be nice if a single transformer worker pass could instead operate on source ranges. However, this is potentially a larger change in how our serializers work, but it's one idea we've seen that looks promising. The long and short of it is that we assume we want to keep the serializer lean even with tree-shaking, prevent uncacheable work, and stop transferring ASTs for tree-shaking to work. |
Summary
Note
Sharing this draft early to get initial feedback and iterate.
Early benchmarking is promising:
Validation so far is based on repeated bundle runs (tree-shake off vs on).
Minimal metro config:
Todo:
unstable_treeShakeflagsideEffectssupportunstable_treeShakeis disabled / not setTest plan
Related issues:
The implementation plan can change depending on react-native-community/discussions-and-proposals#949