this post was submitted on 23 Jan 2025
10 points (85.7% liked)

Rust

7258 readers
5 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
 

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, some of it became 'dead_code' just by removing the pub keyword.

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

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

EDIT: 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.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] KillTheMule@programming.dev 9 points 6 months ago (7 children)

Actually, dead code eliminination should do the trick, if you're compiling a binary at least (same for a library I think, but there could be re-exports there). Did you compile in release mode?

[โ€“] Doods 1 points 6 months ago

Yes I compiled in release mode, but manually removing pub function from dependencies was beneficial for some reason, I really don't want to have to do that.

My release profile:

[profile.release]
opt-level = 3
codegen-units = 1
panic = "abort"
strip = true
lto = true
load more comments (6 replies)