I want to thank the responders who provided examples of compiling settings to create smaller executables. At this stage in my knowledge of Rust, I have no idea what they are doing, and why.
I would suggest (and urge) this knowledge on this topic be included in the Rust Book (documentation) under this topic, as an official guide to Users on how to currently create smaller executables.
However, in raising this issue I had hoped the response would be more along the lines of:
"OK, I see your concerns. Yeh, maybe we need to look into seeing how we can make the executables inherently smaller."
Please, please, please, take this issue seriously.
Let's look at the example that started this.
hello_world.rs
---------------------------
fn main() {
println!("Hello World!")
}
---------------------------
$ rustc hello_world.rs
$ strip hello_world
32-bit Linux 1.8 1.9
rustc 533,943 599,205
strip 309,400 354,504
dif 224,543 244,701
% dif 42.1 40.8
rust/strip 1.73 1.69
64-bit Linux 1.8 1.9
rustc 590,007 654,559
strip 318,952 364,008
dif 271,055 290,551
% dif 45.9 44.4
rust/strip 1.85 1.80
Fundamental Questions
- Why should it take 500+ KBs to create an executable to merely display
Hello World!
?
It is apparent execution efficiency is not currently a design priority for Rust (developers).
And from version 1.8 to 1.9 the efficiency has gotten worse.
As this example shows, the executable increased ~65,000 bytes from version 1.8 to 1.9 on both 32 and 64 bit Linux systems, with 1.9 now taking ~600+ KBs.
We also see the number of unnecessary (stripped off) bytes for the executable also increased by 20KBs.
I see this as a major design flaw, which practically eliminates using Rust on small SBC systems like Raspberry PIs, and their like.
- What has to change in Rust's design to produce (much) smaller executables?
You're not going to like what I think, but I think a complete fundamental redesign of the language would need to occur to put making small executables a design output.
It seems there needs a different partitioning of resources (libraries, etc) that contain the elements that perform the called for tasks, so that the machine code produced is the minimal necessary to do just the desired work.
I understand that being a young language still in early development, the focus is on increasing features and fixing bugs, but creating 'bloatware' needs to be acknowledged, guarded against, and reversed.
- Who are the ultimate users Rust is designed for?
C was created to write Unix in, instead of assembly, to port it to each new machine.
It's still the language Linux, Ruby, and other projects use to get close to bare metal.
Because of its age and heritage, it's much more memory efficient than Rust is now.
I know that part of the reasons most of these new 'system' languages (Rust, D, Go, etc) are so inefficient is because their designers have grown up in an era of memory abundance. I grew up programming in the days of kilobytes of ram and megabytes of disk storage. You read Byte Magazine and Dr Dobbs's Journal to learn how to pinch and scrimp on memory usage. Now you start out on the lowliest of systems with gigabytes of ram and near terabytes of disk storage. And this affects your view on the need to be memory efficient.
But the world is increasingly becoming less about servers and desktops, and more about mobile and small SBCs (again Raspberry PIs, Beagle Boards, etc), and IOT (internet of things) devices. In these domains, memory use efficiency (ram and disk) is still a necessity and priority.
Please, take these as constructive criticisms.
Rust has a lot of great design goals, and potential.
Make producing much smaller/leaner executables a fundamental design goal too.