There is lots of code (tree).
Some of the code is not connected to the entry point (trunk).
Tree shaking removes the disconnected parts (loose leaves, dead branches).
There is lots of code (tree).
Some of the code is not connected to the entry point (trunk).
Tree shaking removes the disconnected parts (loose leaves, dead branches).
In contrast DCE usually refers what the JS engine does at runtime, via whatever means. But DCE isn't much discussed, unless one talking about v8 internals or the like.
Indeed, and this has been known since the 80s as dead code elimination. So why are we using a new, less descriptive, more confusing term again?
Some new developers might be introduced to the concept initially as "tree-shaking". It's not wrong; it just differs from your preference.
Tree-shaking is specifically the form of DCE where you remove unreferenced functions/modules.
Especially important is that you can do tree-shaking without analyzing control flow, while by default "DCE" implies you're analyzing control flow.
And I don't think tree-shaking is a misnomer. Depending on how you visualize the metaphor, unreferenced functions are either barely attached or not attached. Shaking them off is simple and sufficiently realistic.
It's more succient I suppose
And what happens when the wind blows?
Shaking and raking are hardly different in kind.
And wind blowing has what to do with compiler optimizations again?
> Shaking and raking are hardly different in kind.
The only way they're similar is that they're both kinda dumb names for this optimization that has had a standard name for 40 years.
The wind blowing shakes the tree.
When the tree shakes, the dead branches and loose leaves are removed.
---
This is similar to when a bundler will traverse the connected code graph and remove the things that are not attached.
It's no wonder naming things is considered one of the hardest things in computer science if this kind of convoluted argument makes sense to people.
Dead code elimination came 20 years later with C compilers.
The problem with treeshaking - I wrote my first for my lisp 30 years ago, it was trivial - is the lack of compile-time evaluation. The more the compiler knows, the more it can prune. Every run-time branch, late binding and esp. dynamic call by string kills it. With simple tricks you can eliminate 90% of your code. IO, error handling, the number tree, lots of slack in the stdlib's. With GUI even more. I heard from CL images shrinked from 2GB down to a floppy disk.