When I was experimenting WASM with rust, I accidentally found that even very little function was used, the whole std crate seems being included in the final WASM binary, which bloats the final binary about 600 KB. In my experiment, I just wrote a simple crc32.
The full story is in the stackoverflow post, and I already made a simplest demo for this issue.
I already have a temporary work-around for this by manually use no_std, which follows instructions on official document.
I’m not familiar with Rust yet and not sure about posting this here, but I think someone may interested in this issue.
wasm-gc is helpful on this. It shrinks the binary size from about 600KB down to 200KB+. But it's still not enough. In my case, the actual code is only about 1KB. It looks like cargo-wasm uses wasm-gc internally, so the result could be the same. I haven't tried yet.
It's rustc 1.28.0-nightly (2a1c4eec4 2018-06-25), which I believe it's a pretty new version. Demo in Github link should be able to reproduce this issue.
I’ve written some details on this in the past but the tl;dr; is that for the smallest binary size today with the wasm32-unknown-unknown target you need to enable LTO. With LTO I generate a 152-byte binary with today’s nightly.
This story will get better once we upgrade LLD. After that happens if you disable LTO I generate a 158 byte binary by default.