3 ms·
I'm so so so excited to see this land! I have a little hello world demo: https://gist.github.com/steveklabnik/d86491646b9e3e420f8806a286ec8e92 https://gist.gith
by steveklabnik 9y ago
I'm so so so excited to see this land! I have a little hello world demo: https://gist.github.com/steveklabnik/d86491646b9e3e420f8806a286ec8e92 https://gist.github.com/steveklabnik/d86491646b9e3e420f8806a...
To give you an idea of file sizes, the above produces a 116 byte wasm file. If you leave off the no-std stuff it produces a 3059 byte wasm file.
EDIT: I'm actually being told that there was a bug in wasm-gc that's since been fixed, even with libstd it should be able to eliminate all of it and get the tiny file now.
- josephg 9y agoThat’s gorgeous. How much bigger does it grow if you heap allocate? Does it include 2mb of extra code like in normal desktop builds?
- steveklabnik 9y agoI’m away from my computer right now, so may take a while to give you an exact number, but when I first did this, I forgot to turn on optimizations, and the libstd version was 173kb pre-gzip. So I’d imagine it’s similar to that, or at least, that gives you an order of magnitude.
- killercup 9y agoThis Rust code [1] heap allocates some things (e.g., a string with `String::from`), and results in this [2] WASM file, which is 65kB, or 25kB after `gzip -9`. [1]: https://github.com/killercup/wasm-experiments/blob/bf3b30eed6ca73bfc7809f1d87b6604901d3a0b1/examples/hello.rs https://github.com/killercup/wasm-experiments/blob/bf3b30eed... [2]: https://github.com/killercup/wasm-experiments/blob/bf3b30eed6ca73bfc7809f1d87b6604901d3a0b1/hello-wasm.gc.wasm https://github.com/killercup/wasm-experiments/blob/bf3b30eed...
- azakai 9y agoIt should be possible to reduce that a bunch more, 65kB sounds high. Running the binaryen optimizer on that wasm shrinks it by 6%. Probably more can be done on the Rust side.
- killercup 9y agoAbsolutely, yeah. Having a real linker will help with that as well. Until then, you can also compile with [profile.release] opt-level = "s" (i.e., optimizing for size), to get it down to 23kB gzipped.
- josephg 9y agoThats much smaller than I expected, especially given how large rust native binaries usually are. What allocator does that use? Does that 65k include its own malloc implementation like we needed for asmjs, or does WASM expose a system malloc library or something?
- steveklabnik 9y agowasm exposes "memory sections", which the module states up-front how much it wants. It can also generally call a "grow memory" function that makes this space bigger. That's it, from the direct wasm perspective. That said, this target uses https://github.com/alexcrichton/dlmalloc-rs https://github.com/alexcrichton/dlmalloc-rs
- sinhpham 9y agoCould you please add an example of using cargo instead of calling rustc directly? How do I configure cargo.toml?
- steveklabnik 9y agoHere's hello world: https://github.com/steveklabnik/semver.crates.io/commit/dc3bfad678bfdedcc90105ccfdf0d063737a7006 https://github.com/steveklabnik/semver.crates.io/commit/dc3b... (I wanted to try to port semver parsing to the web today, but I hit an LLVM assertion, so it'll have to wait until we can fix that issue. This stuff is still very raw!)