← Back to context

Comment by uticus

5 hours ago

I don't understand what "tree-shaking" means, can you point to a reference to give me a better understanding?

You might know it as "dead code stripping": You remove all the things from the image that aren't used in your shipping app.

Calling it "tree shaking" is web development term AFAIK.

  • > Calling it "tree shaking" is web development term AFAIK.

    I think that's backwards. Lars Bak and the other V8 folks came from the Smalltalk world and brought the "tree shaking" term with them as far as I know.

Tree shaking in this context is not unlike a compiler: it looks at all the code and determines if it will ever run in the image, eliminating any unnecessary code and delivering the minimal image needed. The code is in a “tree” format like an AST, and you’re shaking the tree to test what can be removed.

I used a more recent term known to Web developers.

It means going through the image and remove most code that isn't directly needed by the application, or only exists to support developer workflows.

Usually needs a bit help for fine tuning, regarding what code to keep, and what to delete.

You also find this on Java (jlink, ProGuard, D8/R8 on Android), and .NET (trimming, .NET Native manifests).