DEV Community

Discussion on: First Week learning rust

Collapse
 
deciduously profile image
Ben Lovy

I don't know about Go, so I can't speak for that. With Rust, you're seeing these sizes due to static linking, and symbols being included in the binary. On Linux, a hello-world compiled with --release generates a 3.7M executable. Just running strip on this executable reduces the size to 310k. You can also se size-related optimizations in your profile:

[profile.release]
opt-level = "z"
lto = true
Enter fullscreen mode Exit fullscreen mode

Other tweakables include panic behavior - you can remove the unwinding mechanism using this:

[profile.release]
panic = "abort"
Enter fullscreen mode Exit fullscreen mode

So, yes, while the defaults produce some hefty executables, Rust does expose tools to more finely tweak your result. This repo provides a much more comprehensive overview.

Thread Thread
 
lexiebkm profile image
Alexander B.K.

Thanks for the answer. This is just a start for my journey of Rust. I have a plan to try it for web backend after reading your post about it. We know that the book also has a chapter on web server that I can use for starting point.