4 ms·
250K for hello world example... where is this world going to! :) I am sure it can be trimmed, but we are getting oblivious to common sense a little. This is sy
by desireco42 11y ago
250K for hello world example... where is this world going to! :)
I am sure it can be trimmed, but we are getting oblivious to common sense a little. This is system language.
- tatterdemalion 11y agoBy default Rust statically links the standard library into every program. For binaries it also statically links to jemalloc by default to use as the allocator. This is a large constant factory that makes trivial programs significantly larger than C, but like all constant factors it becomes insignificant when n is larger. Binary size is not a major concern for most programs, even those written in a systems language. If it is a concern for your use case, you can use dynamic linking and the system allocator to get the size down to the same scale as C.
- Manishearth 11y agoThat 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
- ternaryoperator 11y agoThe great wit, Stan Kelly-Bootle, once observed (about Turbo C): "It generated a 40KB executable when I wrote my first 'Hello, World!' program. After that, I dared not say 'Goodbye.'"
- desireco42 11y agoFinally someone understands what I wrote, thanks man
- pcwalton 11y agoI read the exact opposite point.
- zerr 11y agoOn the contrary, when Borland C++ Builder (i.e. "Delphi for C++") generated an executable for the app with a GUI, my first reaction was - it's so small, no way this can be a standalone executable, I can't give this to client... :)
- lifthrasiir 11y ago$ cat hello.rs fn main() { println!("Hello, world!") } $ rustc hello.rs -C prefer-dynamic $ ./hello Hello, world! $ ls -al hello -rwxrwxr-x 1 lifthrasiir 9064 Mar 4 14:24 hello* See other comments for the explanation.
- whyever 11y agoYou can go under 1k if you don't use the standard library: https://github.com/retep998/hello-rs https://github.com/retep998/hello-rs
- Ygg2 11y agoYou can go 151 bytes if you are ready to do some link shenanigans: http://mainisusuallyafunction.blogspot.rs/2015/01/151-byte-static-linux-binary-in-rust.html http://mainisusuallyafunction.blogspot.rs/2015/01/151-byte-s...