4 ms·
Another point against Rust is binary size. If you write the Fibonacci generator in one of the first chapters of the Rust book it will create a 4MB binary. Even
by kungtotte 8y ago
Another point against Rust is binary size.
If you write the Fibonacci generator in one of the first chapters of the Rust book it will create a 4MB binary. Even stripped it's over 400KB.
If you write the same code in Nim it compiles down to 112KB with debug symbols, unstripped. Statically linked against libc (still with debug symbols) it's only 850KB.
850KB statically linked versus ~450KB dynamically linked and stripped.
For code that is virtually identical.
- danieldk 8y agoRust binaries include jemalloc. However, jemalloc is removed in nightly and by default Rust will use the system allocator: https://internals.rust-lang.org/t/jemalloc-was-just-removed-from-the-standard-library/8759 https://internals.rust-lang.org/t/jemalloc-was-just-removed-... This should reduce binary sizes quite a bit.
- vesak 8y agoAnd some rough numbers, rustc-1.30.1 vs rustc-1.32.0-2018-11-21, building a hello world with --release... Mac OS: - 1.30.1 before strip: 573K, after strip: 380K - 1.32.0 before strip: 267K, after strip: 178K Ubuntu 18.04 LTS: - 1.30.1 before strip: 3.9M, after strip: 407K - 1.32.0 before strip: 2.3M, after strip: 191K
- kungtotte 8y agoI'm on Void Linux right now running Nim 0.19 compiling the following code: when isMainModule: echo "Hello World" nim c hello.nim: Before strip: 113k After strip: 92k nim c -d:release hello.nim: Before strip: 79k After strip: 63k nim c -d:release --opt:size hello.nim: Before strip: 46k After strip: 30k Kind of a toy example but it illustrates my point. An unstripped version of the Nim program with full debug symbols is still 78k smaller than the stripped, release version of the Rust equivalent. But it's great that they're trying to work on this problem.
- nimmer 8y agoThe difference gets bigger on large binaries.
- vesak 8y ago>But it's great that they're trying to work on this problem. I don't know how the Rust team thinks, but I believe that minimizing binary sizes is not a very big priority for them. The cost of a gigabyte these days is, ~0.01$ (or less) for local hard drives, $0.4 for NVME and about $0.1 for AWS EBS... Technically of course it's cool how small Nim binaries are, and it does make certain things feasible which with larger binary sizes might be difficult.
- steveklabnik 8y agoWe think it's important to be able to control it if you need to, and have done work to make that possible. But we don't worry about the default too much, as you say, we've got a lot of things to worry about, and it's not near the top of the list. That said, the smallest executable produced is 145 bytes: https://github.com/tormol/tiny-rust-executable https://github.com/tormol/tiny-rust-executable
- weavie 8y agoHow far does this scale? What are the binary sizes of a 100k loc app in Rust vs Nim?
- nimmer 8y agoSee reply from kungtotte
- adaszko 8y agoDoes this matter anywhere outside of embedded software nowadays?
- eeZah7Ux 8y agoYes: security sensitive applications where being able to inspect or fuzz a binary is strongly dependent on size. Also firmware on servers.
- steveklabnik 8y agoRust has really strong fuzzing support, incidentally https://github.com/rust-fuzz/cargo-fuzz https://github.com/rust-fuzz/cargo-fuzz
- eeZah7Ux 8y agoSo does C and other languages.