In computing, tree shaking is a dead code elimination technique that is applied when optimizing code. Often contrasted with traditional single-library dead code elimination techniques common to minifiers, tree shaking eliminates unused functions from across the bundle by starting at the entry point and only including functions that may be executed. It is succinctly described as "live code inclusion".
Dead code elimination in dynamic languages is a much harder problem than in static languages. The idea of a "treeshaker" originated in LISP in the 1990s. The idea is that all possible execution flows of a program can be represented as a tree of function calls, so that functions that are never called can be eliminated.
The next wave of popularity of the term is attributed to Rich Harris's Rollup project developed in 2015.
Relation to ECMAScript 6 modules
- ^ Harris, Rich. "Tree-shaking versus dead code elimination". Retrieved 16 September 2020.
- ^ a b Ladd, Seth. "Minification is not enough, you need tree shaking". Seth Ladd's Blog.
- ^ comp.lang.lisp What's a treeshaker?