3 ms·
That 250K is additive, not multiplicative. Hello World, which might be 10K in C, will be 240K+10K=250K in Rust. A larger program that would be 2M in C would be
by Manishearth 11y ago
That 250K is additive, not multiplicative. Hello World, which might be 10K in C, will be 240K+10K=250K in Rust. A larger program that would be 2M in C would be 240K+2M in Rust; the significance of that 240K reduces when you write actual programs (instead of hello world).
The size is due to a statically linked stdlib (also jemalloc, which you can decide not to use) -- your C program is tiny because your system has a stdlib it can dynamically link to. Rust can do this too, it's just not the default since in most cases this additive extra binary size isn't a problem.
Being a systems language does mean we should forgo sensible defaults.
- mystikal 11y agoIn theory you could tell the compiler to identify and statically link only those functions needed to make printf work (or a conservative approximation thereof).
- danieldk 11y agoAs far as I know, jemalloc is a substantial part of that binary size. See e.g.: https://github.com/japaric/rust-on-openwrt/issues/1#issuecomment-108425440 https://github.com/japaric/rust-on-openwrt/issues/1#issuecom... https://github.com/japaric/std-with-cargo#making-rust-binaries-smaller https://github.com/japaric/std-with-cargo#making-rust-binari...
- Manishearth 11y agoYeah, that's just running LTO (`-C lto`). This brings the binary size down a bit, thought you also need to opt out of jemalloc to get a good impact.
- Manishearth 11y agoEdit: *doesn't