Stripping debug info in the release profile reduces my crate's binary size by a third (from 1.9 MB to 1.3 MB). This is what I added:
[profile.release]
strip = true
# or strip = "symbols"
Why is stripping disabled by default in the release profile?
I read the section on strip cargo option but I'm still a bit unsure about its internals.
Are there any cons of always using it in the release profile - perhaps only increasing compilation time?
Debug info is, well, information that is useful in debugging. In particular, certain parts of the binary are mapped to source code in a way that helps you debug a
--releasebinary.For example, given this code:
The stacktrace with debug info included looks like this (running
RUST_BACKTRACE=full cargo run --release):Without debug info, it looks like this:
As a rule of thumb, I leave it on (i.e. I don't strip debug info) unless I really really care about binary size.