Comment by nindalf

1 day ago

> a debug build of "hello world!" in Rust clocks in at 3.7mb. (No shade on Rust)

This isn't true. It took me two seconds to create a new project, run `cargo build` followed by `ls -hl ./target/debug/helloworld`. That tells me it's 438K, not 3.7MB.

Also, this is a debug build, one that contains debug symbols to help with debugging. Release builds would be configured to strip them, and a release binary of hello world clocks in at 343K. And for people who want even smaller binaries, they can follow the instructions at https://github.com/johnthagen/min-sized-rust.

Older Rust versions used to include more debug symbols in the build, but they're now stripped out by default.

$ rustc --version && rustc hello.rs && ls -alh hello

rustc 1.84.1 e71f9a9a9 2025-01-27 -rwxr-xr-x 1 user user 9.1M hello

So 9.1 MB on my machine. And as I pointed out in a comment below, your release binary of 440k is still larger than necessary by a factor 2000x or so.

Windows 95 came on 13x 3.5" floppies, so 22MB. The rust compiler package takes up 240mb on my machine. That means rust is about 10x larger than a fully functional desktop OS from 30 years ago.

  • Fwiw, in something like hello world, most of the size is just the rust standard library that's statically linked in. Unused parts don't get removed as it is precompiled (unless there's some linker magic I am unaware of). A C program dynamically links to the system's libc so it doesn't pay the same cost.

    • You can statically link a C program and only parts of libc that are used are included in the binary.

  • Before a few days ago I would have told you that the smallest binary rustc has ever produced is 137 bytes, but I told that to someone recently and they tried to reproduce and got it down to 135.

    The default settings don’t optimize for size, because for most people, this doesn’t matter. But if you want to, you can.

  • > And as I pointed out in a comment below, your release binary of 440k is still larger than necessary by a factor 2000x or so.

    This is such a silly argument because nobody is optimizing compilers and standard libraries for Hello World utilities.

    It's also ridiculous to compare debug builds in rust against release builds for something else.

    If you want a minimum sized Hello World app in rust then you'd use nostd, use a no-op panic handler, and make the syscalls manually.

    > The rust compiler package takes up 240mb on my machine. That means rust is about 10x larger than a fully functional desktop OS from 30 years ago.

    Fortunately for all of us, storage costs and bandwidth prices have improved by multiple orders of magnitude since then.

    Which is why we don't care. The added benefits of modern software are great.

    You're welcome to go back and use a 30 year old desktop OS if you'd like, though.

  • rustc --version && rustc main.rs && ls -alh main

    rustc 1.85.0 (4d91de4e4 2025-02-17) -rwxr-xr-x 1 user user 436K 21 Feb 17:17 main

    What's your output for `rustup default`?

    Also, what's your output when you follow min-sized-rust?

For me,

3.8M Feb 21 11:56 target/debug/helloworld

  • Why is not —release being passed to cargo? It’s not like the File Pilo mentioned by GP is released with debug symbols.

    • The original post/blog said a debug hello world was 3.7MB. I confirmed the post.

      A release build is:

      426K Feb 21 15:28 target/release/helloworld

      If you use lto, codegen-units = 1 and strip then you get:

      323K Feb 21 15:30 target/release/helloworld