3 ms·
I just programmed a function, which added 2 numbers and compiled it and got a huge binary. But maybe I did something wrong. I will try again. Thanks.
by s-macke 8y ago
I just programmed a function, which added 2 numbers and compiled it and got a huge binary. But maybe I did something wrong. I will try again. Thanks.
- the_duke 8y agoWhich target are you using?
- s-macke 8y agoI can tell you in a few hours. But it would be easier if you provide me the correct compile options to produce such a small binary for trivial functions. Target was of course the webassembly target.
- steveklabnik 8y agoThere's two wasm targets; one with emscripten, one without. It sounds like you were using the one without, which is generally the right one.
- ColinEberhardt 8y agothe tooling is quite immature at the moment - and tools like Emscripten especially add a lot of bloat. In the future wasm modules will be a lot slimmer. The Rust community are certainly leading the way on that one.
- maeln 8y agoI you did the naive add two number example, you probably also included the whole standard library. If you really want to go down in size, you either need to compile without the standard library and/or use wasm-gc and wasmopt to remove all the useless code that have been added to your wasm binary. With this, you can generate wasm binary that weight only a few hundreds octets.
- steveklabnik 8y agoThere's a lot of stuff going on. Depending on which rust you used, we didn't do a lot of dead code elimination by default, and the default settings don't optimize for size. The 100 byte thing is the "add two numbers" function, but you have to do a few things. See here: https://rustwasm.github.io/book/game-of-life/code-size.html https://rustwasm.github.io/book/game-of-life/code-size.html In the future, it will do more of the right things by default, but for now, you have to do some configuration if you want the tiniest possible binary. Early days!