Auto debloat unused pub items from dependencies

I shaved off 10 MiB from my binary in 2 hours!

I made a program using Macroquad, then I built it in release mode, the binary was 63 MiB in size.

So I used cargo vendor to have a better look at Macroquad and one of its dependencies, glam.

I then started to delete code, like, lots and lots of code(about 30_000 lines of code); none of it affected my main project.

The result is that my project was unaffected and the binary went down to 52 MiB.

As it currently stands, the Rust compiler doesn't flag unused pub items as dead code, even when building a binary crate.

Is there a way to automate removal of unneeded elements from dependencies? This is potentially huge.

Link to Lemmy version of this post

My release profile:

[profile.release]
opt-level = 3
codegen-units = 1
panic = "abort"
strip = true
lto = true

All unused functions should already get removed by the linker. Are you on Windows by any chance? That is the only platform where we are forced to disable this functionality due to running against limitations in the COFF file format.

1 Like

No, I'm on Pop!_OS 24.04 (essentially just Ubuntu 24.04).

Most of the space saved was by deleting the modules of glam related to anything besides f32, which was a few big modules.

I FIGURED IT OUT!!!

My mistake was measuring the size of "target/release", I discovered that that folder contains many "unnecessary" files, like "deps", which greatly bloat the folder'r size, the actual size of my binary is 864K.

I am so relieved.