2 ms·
> Even a basic hello world in rust will set you back a few megabytes Lies. It’s 35 kB: $ cargo new x … $ cd x $ cat src/main.rs fn main() {
by chrismorgan 10mo ago
> Even a basic hello world in rust will set you back a few megabytes
Lies. It’s 35 kB:
$ cargo new x
…
$ cd x
$ cat src/main.rs
fn main() {
println!("Hello, world!");
}
$ cargo build --release --target=wasm32-unknown-unknown
…
$ ls -l target/wasm32-unknown-unknown/release/x.wasm
… 34597 …
And that’s with the default allocator and all the std formatting and panic machinery. Without too much effort, you can get it to under 1 kB, if I remember correctly.
For the rest: I mention comparisons being unbalanced because people often assume it will scale at the rate they’ve seen—twice as much code, twice as much size. Runtimes and heavy tables make for non-scaling overhead. That 35 kB you’ve paid for once, and now can use as much as you like without further growth.
- hajile 10mo ago35kb is the size of a lot of entire JS frameworks.
- chrismorgan 10mo agoI should also mention that that 35 kB is uncompressed—gzipped, it’s 13 kB, and with brotli it’s 11.3 kB. Meanwhile, an empty React project seems to be up to 190 kB now, 61 kB gzipped. For startup performance, it’s fairly well understood that image bytes are cheap while JavaScript bytes are expensive. WebAssembly bytes cost similar to images.