|
|
|
|
|
by brabel
1151 days ago
|
|
Exactly, WASM was designed to be very very lightweight... you can put a lot of logic into a very small amount of WASM, but you need a good compiler to do that, or write WASM by hand to really feel the benefit. If you just compile Go to WASM, with its GC, runtime and stdlib included in the binary, yeah it's going to be pretty heavy... Rust doesn't have a runtime but as you said, for some reason, produces relatively large binaries (not the case only in WASM by the way). Probably, the best ways to create small WASM binaries is to compile from C or from a WASM-native language like AssemblySCript (https://www.assemblyscript.org). |
|
- A custom panic message (so you know which line of code crashed)
- Some monomorphized formatting code to output that message
- The infrastructure to generate a stack trace after a panic
- Logic to free all the allocated objects all the way up the stack
If you compile this 1 line function:
... You produce 20 hairy lines of assembler: https://rust.godbolt.org/z/dhz34KEvjIn contrast, the equivalent C function is this rust code:
And predictably, the result is this gem - identical to what the C compiler outputs: But nobody writes rust code like that (for good reason). You can get a lot of the way there by leaning heavily using rust's iterator types and such. But its really difficult to learn what patterns will make the rust compiler lose its mind. There's no feedback on this at compile time, at all.