this post was submitted on 11 Jul 2023
14 points (93.8% liked)
Programmer Humor
32444 readers
938 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
When I compiled that program, the executable was around 10MB. I wrote the same program in C, and the executable was 15kB. That's about 3 orders of magnitude difference. Is Rust really 1000 times better than C? :-)
The standard lib is statically linked, so there will be a higher baseline binary size. This means that yes, a hello world project may be 10mb unstripped but a considerably more complicated project could in turn be 11mb unstripped. Aka it doesn't matter much in practice.
Enable LTO, abort on panic, and a higher optimization level and it'll drop that a ton
I wrote it in C and compiled it for an ATtiny13 and it was 162 bytes. That includes the code to initialize the microcontroller and a bit banged transmit only UART to actually output the text.
just goes to show: size is relative :-)
set opt level to 3 and enable fat lto.
even without fat lto enabled, my entire multithreaded voxel engine with multithreaded procedural world generation, procedural structures and multiplayer is 5mb in size.
Rust turns a lot of safety things 'on' by default.
Turning all of that off for a tiny program that doesn't need it such as hello world results in a comparable size.
This is a good talk on rust
https://youtu.be/VlSkZYBeK8Q
And this one goes over size reduction
https://youtu.be/b2qe3L4BX-Y
this is not due to safety but rather std. Set opt level to 3 and enable fat lto