Live data from Hacker News

Making Rust binaries smaller by default

kobzol.github.io

21–30 of 199 posts

Re: Making Rust binaries smaller by default

#22

Earlier quoted context omitted.

That’s almost never the case, though. Imagine if a C binary statically linked in libc. Adding a page full of more C to its code would only grow it a tiny amount.

I would hope that it could statically link libc and exclude the unreachable portions.

Rust can't do this very well because it doesn't build std as part of the project, that's still an unstable option. It's linking object code.

Re: Making Rust binaries smaller by default

#24

So what's in the remaining huge 415KB hello world program? Can we get rid of 90% of it a couple more times?

Mostly the formatting machinery from stdlib. You can go sub 100 KiB or even less without it, but unless you target embedded, there's really a reason to do that, IMO.

Re: Making Rust binaries smaller by default

#26

not a rust programmer. can someone explain why this is in the final binary and not in a shared library?

The Rust compiler statically links everything into a single binary. This can be changed, but is generally discouraged as there are no ABI stability guarantees at this point.

You can use the C ABI if you want something stable, and there are custom crates that will help with translating from the Rust to the C ABI. (This also helps because the resulting shared objects can potentially be FFI'd with from any language, not just Rust. They might as well be plain C libraries as far as anyone is concerned, only with the usual Rust safety requirements.)

Re: Making Rust binaries smaller by default

#29

"Rust tries to appeal to programmers coming from many different backgrounds, and not everyone knows that something like stripping binaries even exists."

It's not ideally written but it's safe to assume if someone compiles a quick test program for that purpose and it ends up being 4MB, they might just move on to other options instead of starting to think about how they can manually reduce the binary size.

When evaluating languages, you rarely look foor good enough results to work around.

Re: Making Rust binaries smaller by default

#30

It's great to see rust maturing. That people care about binary size and work to improve it is a good sign.

It's not a great sign that this bug existed for 7 years, people noticed, asked about it, wrote tickets, everybody agreed that it should be fixed but then nobody took the time to actually do it (and the eventual fix is a rather crude hack by just stripping the output binary instead of preventing that debug symbols slip into a release binary in the first place).

Looks more like a systemic issue in the Rust development process to me tbh.

What's more shocking though is that even after a 90% size reduction, a vanilla hello world is still 415 KBytes. That's about 10..100x bigger than I would expect from a low level "systems programming language".

Post reply on HN