this post was submitted on 23 Jan 2025
6 points (80.0% liked)

Rust

6244 readers
16 users here now

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

Wormhole

[email protected]

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
[–] [email protected] 1 points 1 day ago* (last edited 1 day ago) (1 children)

Yes, I am using both LTO and release mode, I can show you:

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

cargo build --release

[–] [email protected] 1 points 1 day ago (1 children)

@Doods I'm surprised you can gain that much with that already enabled!

[–] [email protected] 2 points 1 day ago* (last edited 1 day ago) (1 children)

Should I bring it up to the 'min-sized-rust' working group or the forums or something?

[–] [email protected] 4 points 23 hours ago (1 children)

Yes. This behavior seems strange, so either an explanation or investigation by a compiler dev seems like it would be helpful.

[–] [email protected] 2 points 1 hour ago

Just so you know I figured it out, re-read the post please.