Hacker News new | ask | show | jobs
by speps 864 days ago
8MB seems high for Rust. Even the project I did [1] which was using D (with GC) ended up with an 8MB WASM. Rust's WASM target is much more exercised than D's, so I think you might need to tweak some compile options.

[1] https://github.com/speps/tt

3 comments

That's possible. I did spend quite a bit of time tinkering with compiler flags and followed the recommendations, but there is many knobs.

For what it's worth I don't think 3MB is extremely large anymore, as several popular websites already weight in 2-3 MB for a full page loads.

Examples:

  * www.youtube.com = 3.3 MB
  * www.tiktok.com = 3.3 MB
  * www.instagram.com = 2.1 MB
(according to https://www.supermonitoring.com/p/page-speed)

That said, I would love to shave off more size off my wasm binaries :-)

Some notes I found just now seems to be in line with my results, though: https://github.com/bevyengine/bevy/issues/3978#issuecomment-...

FWIW, this is my relevant Cargo.toml settings:

  [profile.release]
  lto = "fat"
  codegen-units = 1
  opt-level = 3
  debug = false
  panic = "abort"
  strip = "debuginfo"

  [profile.wasm-release]
  inherits = "release"
  opt-level = "z"
Rust binaries seem to be larger than they should be, though. I believe Kobzol [1] has been making some work on that.

[1]: https://kobzol.github.io/rust/cargo/2024/01/23/making-rust-b...

(Not op)

I agree that 8MB seems high. I can generate a 6MB binary using `--debug` with `wasm-pack` so definitely for a more complex thing I could see 8MB. I think `--release`, `codegen-units = 1`, `opt-level = 3/z` are the three biggest things that affect binary size for me.

I don't think 8MB is that big a deal for a web game though. Like how large are the images? If you're going to dynamically load in like 50+ MB of assets then having an initial game of 8 MB is the small pole in the tent. I have my stuff setup as a PWA so once everything has been downloaded it takes 0 MB on the wire to open a second time; you could set-up the game as 2 binaries; one super-small one that just basically handles an opening cinematic and a larger one that can actually play the game which is downloaded while the cinematic plays (or is cached in future opens).