Hacker News new | ask | show | jobs
by reacharavindh 2941 days ago
I have just started playing with Actix-web. Rust-Noob as well. The yellow world example compiled to a binary that was ~ 5 MB.

As a general case, Actix-web pulls in a lot of dependencies at install, and compile time.Are all of those dependencies really necessary for a hello world scenario?

Being a Rust newbie, I thought maybe I was using the wrong tool and started to look at hyper instead..

3 comments

5MB is nothing compared to what you'd use for a similar project in node or Python or Ruby. Sure, it's not the tiniest it could be, but using tools like strip, not including debug symbols etc it gets pretty damn small. Honestly though, at that point I think size becomes entirely pointless to even mention unless you need to run it in a super constrained environment, which you're probably not when you're using the standard library :)
There's a lot that can be done to shrink a Rust binary[0]. A copy of the summary:

- Compile with --release.

- Before distribution, enable LTO and strip the binary.

- If your program is not memory-intensive, use the system allocator (assuming nightly).

- You may be able to use the optimization level s/z in the future as well.

- I didn’t mention this because it doesn’t improve such a small program, but you can also try UPX and other executable compressors if you are working with a much larger application.

[0]https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab...

s/z was made stable ten days ago: https://github.com/rust-lang/rust/pull/50265

So, two releases :)

Yes, I'm not constrained in any way to not be able to run a 5 MB binary. I was curious if that was an indication of what is to come for large projects...

I guess I was tangentially pointing to complexity and abstraction there.

rust doesn't use dynamic linking, which contributes a lot to that size.
Wont a crate compiled with 'crate_type = "dylib"' be dynamically linked if you specify '-C prefer-dynamic' when compiling your program?

https://doc.rust-lang.org/reference/linkage.html

This is pedantic, but rust does link dynamically, but only to libc.
It can, but for practical reasons, generally does not. For Rust code anyway; often anything bound via FFI is dynamically linked.
> I have just started playing with Actix-web. Rust-Noob as well. The yellow world example compiled to a binary that was ~ 5 MB.

I've only played around with Rust a bit, but IMO, as a general rule: don't judge back-end frameworks by the size of the deliveries, unless we're talking about something ridiculous (5GB). It's extremely superficial and has a very low correlation with the quality of the actual tool.

> The yellow [sic] world example compiled to a binary that was ~ 5 MB.

See: "Why are Rust executables so huge"

https://stackoverflow.com/questions/29008127/why-are-rust-ex...