3 ms·
Pretty nice and it's what I suspected. I still wish at one point binary sizes are taken seriously though. But I am aware that it's likely (a) not at all a prio
by pdimitar 4y ago
Pretty nice and it's what I suspected.
I still wish at one point binary sizes are taken seriously though. But I am aware that it's likely (a) not at all a priority currently, and (b) a gigantic effort.
- steveklabnik 4y agoI’m not sure what “taken seriously” would mean to you, but I work in embedded. We get the Rust compiler to spit out programs in the hundreds or thousands of bytes regularly. Binary sizes are more about the people doing the programming than the compiler missing some sort of crucial technology.
- pdimitar 4y agoI get that this is possible with `no_std` but that's not an option for me. Guess I'll dig out the guides for reducing binary sizes but last time I needed tokio + opentelemetry + a Prometheus adapter my release binary was always at least 5MB. Also sorry, didn't mean to come off as dismissive. It's just that to me 5MB is quite a lot and should be shrinkable. I keep wondering if the compiler/linker tech can help Rust there.
- steveklabnik 4y agoIt’s all good! I don’t think you were being dismissive at all. I don’t even contribute to the Rust project anymore, and in fact wish they’d prioritize various toolchain improvements. Just in this specific case I don’t really think there’s anything to be done. All the standard stuff is already in there. But maybe I’m wrong!
- mwcampbell 4y agoIs that 5MB with or without symbols? Note that on Linux, binaries aren't stripped by default. Having said that, if your binary ended up including a hyper-based HTTP server and a TLS implementation, and was built with the default release profile (optimizing for speed rather than size), I can believe it would reach 5MB stripped.
- pdimitar 4y agoYeah it's picking quite a lot of baggage by using the relatively short list of deps. Debug symbols stripped it clocks at 5.9M, all symbols stripped it's at 5.0M. Obviously this is not critical. But I have to admit I envy Zig and OCaml. :)
- mwcampbell 4y agoIf you can easily rebuild the project, I wonder what the binary size is if you add this to your top-level Cargo.toml: [profile.release] codegen-units = 1 lto = "fat" opt-level = "z" panic = "abort" Take out that last line if you need to recover from panics at runtime. So far, in my limited use of Rust, I haven't had to. Anyway, those are all the easy tweaks to reduce binary size.
- pdimitar 4y agoHad the first two already. I always prefer to optimize for speed and not size but just for the heck of it I enabled it. Wasn't super sure about the panic thing so I never used it but your comment is reassuring so I will just leave it in. From 5.0M to 3.0M, not bad! Turned the optimization for speed back on -- 4.4M! Wow.