4 ms·
This might be a little side-topic but IMO Alpine is famous for having a small byte size footprint. I love Rust to tears but it produces fairly huge binaries ev
by pdimitar 5y ago
This might be a little side-topic but IMO Alpine is famous for having a small byte size footprint.
I love Rust to tears but it produces fairly huge binaries even in release mode and even with some symbols stripping.
So if Alpine also plans to include various Rust tools I'd hope that this will prompt the core team to also work on reducing the sizes of the final Rust binaries.
I don't want to sound entitled! I am very thankful to the entire Rust team. And Rust is hugely important nowadays. It's just that when it comes to distributing stuff in Dockerfiles (and fly.io, and several others) the Rust binaries stick out like a sore thumb. :\ They're fairly big.
- dijit 5y agoIs alpine really going for “small” though? I’m not saying they’re not small and haven’t done a fantastic job, but my impression is that this is due to being mostly minimal in the default install; The reason I say this (and I could be wrong) is because the use of musl for the libc means each binary kinda needs to include it’s own libc statically. This must make the binaries huge! Also, you can easily make small rust binaries, it’s Golang (of the two) that produces very large binaries. If you just follow the first two bits of advice from: https://github.com/johnthagen/min-sized-rust https://github.com/johnthagen/min-sized-rust you’ll reduce your binary sizes to near C++ levels.
- AndyKelley 5y ago> the use of musl for the libc means each binary kinda needs to include it’s own libc statically. This is factually incorrect. Musl supports dynamic linking and if you run `ldd` on any binary in Alpine you can see that it dynamically links against musl libc.
- dijit 5y agoAh, fair enough. I did a little more digging and it seems you can dynamically link rust binaries too now: https://github.com/rust-lang/compiler-team/issues/422 https://github.com/rust-lang/compiler-team/issues/422
- deleted 5y ago[deleted]
- psd1 5y agoIn your link, I really enjoyed this link on creating a 45-byte executable: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
- phendrenad2 5y agoTrust in open-source's ability to populate all niches. If Rust is added, and it significantly bloats up the Alpine image, someone will come along and make Alpine-Classic or Montane Linux or something.
- raggi 5y agoThis is definitely an area it would be great to see more work in. On Fuchsia we started linking the rust stdlib dynamically, but there are some significant ABI constraints to doing this in a traditional Unix shared library ecosystem that we're able to avoid due to the isolated and storage-deduplicated nature of the package system. If you do link rusts stdlib dynamically, then you end up with binaries that are equivalent to C++ binary sizes with an external libc++, where rusts stdlib is approximately the same size as libc++, and the release mode stripped binaries are also comparable (within ~1kb of each other, and in the range of 10kb for a standard unix pipeline style application which does some basic stream processing of IO).
- pdimitar 5y agoI am definitely not as well-versed as you -- but for now I'd stick with Rust's statically linking nature. What I am more looking for is to have some very aggressive tree-shaking at the final phases of Rust compilation/linking where the tooling can prove that in your program, say, 73% of the stdlib isn't used at all so it can just remove it from the final binary. It's my view that as deployment moves more and more to containers and even to the "microkernel + your app only" model then being able to fit binaries in CPU caches will become crucial for the viability of such cloud hosting. (Although to be fair, when we're talking about Rust + the Linux kernel, running something in 25ms vs 5ms can't be a huge deal for 98% of all apps, right?)
- vvanders 5y agoPretty sure LTO already provides that functionality(I wish Rust had LTO on by default but it's fairly straightforward to flip on).
- pdimitar 5y agoYou can set LTO units to 1 which is what I do because it leads to some final binary size reduction -- but it isn't much. :( I am aware that we have to start being more mindful of our dependencies but in commercial this is a luxury that you often don't have.
- gizdan 5y agoMaybe I'm misunderstanding but from what I understood, this isn't about adding rust to the base alpine packaging. It's about showing it to be installed from the main repository. Currently it's available in the community repository.
- pdimitar 5y agoAh, you understand me (and the post) just fine -- hence I mentioned that my comment is a bit out there and not exactly on topic. I am simply wondering if this would prompt more interest in reducing Rust's final binary sizes, that's all.
- pdimitar 5y agoNot sure why I am eating the down arrows but I'd like to specify: I just tested on a few projects of mine and the binary size reduction is definitely more aggressive and better-looking compared to a year ago. Very happy with the gains! I am leaving my original comment above anyway since there's IMO still some room for improvement. For comparison, without LTO and stripping I've had a fairly small hobby project easily compile to ~3MB and with them it's now ~800KB which is nearly 400% improvement. Nice.
- speed_spread 5y agoDocker acts as late linker for dynamically linked apps, bundling shared libs and executable together. Statically linked Rust apps certainly go against the grain in that model but can often be made significantly smaller with some build and dependency tweaking.