Re:Announcing Rust 1.7
by Manishearth on Thursday March 03, 2016 @10:46PM
(#11221953)
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.
In theory you could tell the compiler to identify and statically link only those functions needed to make printf work (or a conservative approximation thereof).
As 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#issuecom...
https://github.com/japaric/std-with-cargo#making-rust-binari...
Re:Announcing Rust 1.7
by Manishearth on Friday March 04, 2016 @04:35AM
(#11222822)
Yeah, 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.
Re:Announcing Rust 1.7
by Manishearth on Friday March 04, 2016 @04:31AM
(#11222819)
Edit: *doesn't
Re:Announcing Rust 1.7
by tatterdemalion on Thursday March 03, 2016 @10:11PM
(#11221835)
By 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.
Re:Announcing Rust 1.7
by lifthrasiir on Friday March 04, 2016 @12:25AM
(#11222191)
$ 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.
Re:Announcing Rust 1.7
by ternaryoperator on Thursday March 03, 2016 @11:17PM
(#11222015)
The 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.'"
On 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... :)
Re:Announcing Rust 1.7
by desireco42 on Friday March 04, 2016 @12:00AM
(#11222121)
Finally someone understands what I wrote, thanks man
I read the exact opposite point.
You can go under 1k if you don't use the standard library: https://github.com/retep998/hello-rs
You can go 151 bytes if you are ready to do some link shenanigans:
http://mainisusuallyafunction.blogspot.rs/2015/01/151-byte-s...
I am sure it can be trimmed, but we are getting oblivious to common sense a little. This is system language.