Tree shaking before compiling?

Is there a way to remove unused code from the binary application, along with the used crates?

From my limited understanding of the compilation process, compiling all the code in all the hundreds of crates commonly used to build any usable project of any significant size, takes compilation times throw the roof and beyond. Is there a way to do what Angular tooling does in the world of Rust?

See Towards a second edition of the compiler

1 Like

The focus in Rust is more to skip over pointless work as soon as possible in the compilation process, in order to speed up rustc. But one way or another unused functions, branches, or modules will never be present in finished production binaries. And if anything, Angular's tree shaking is an attempt to do what languages like C have done for decades.

2 Likes

See also: Why can't `rustc` only compile code that is actually used? - The Rust Programming Language Forum

1 Like