4 ms·
There is one huge change here (as compared to things like the golang wasm port) which makes this more likely to be adopted IMO: Rust compiled to WebAssembly do
by grey-area 8y ago
There is one huge change here (as compared to things like the golang wasm port) which makes this more likely to be adopted IMO:
Rust compiled to WebAssembly doesn’t have a runtime. This results in small .wasm binary sizes that are proportional to the amount of Rust code that is being compiled to WebAssembly. Binary size is of huge importance since the .wasm must be downloaded over the network. The proportionality means you only pay (in code size) for what you use. In turn, that means it is feasible for existing JavaScript code bases to incrementally and partially adopt Rust.
Great to hear they're taking this approach. I do think it'd be nice to have DOM access too though, as then you won't need JS at all - I do think long term the attraction of this is to replace JS as a front-end language, not just augment it, but it's nice they're taking an incremental approach.
- brighteyes 8y agoIt depends how you define "runtime", though. If you use Rust strings, you may get a large amount of code included to handle them. Also, if you use malloc, that adds a significant amount of code. It's true that languages like Rust have fewer runtime requirements than languages like Java but none of them are 100% proportional to the code you wrote.
- steveklabnik 8y agowasm-bindgen is forward compatible with the host bindings proposal, so once that lands, the DOM stuff will Just Work.
- crudbug 8y agoWaiting for this !
- seanatyc 8y ago"as compared to things like the golang wasm port" -- I have two questions here. First, can you elaborate the difference between the current Golang was port and proposed Rust wasm port? Secondly, can you elaborate why Golang port can't have small .wasm size?
- steveklabnik 8y agoGo has a mandatory runtime (think, the GC) that needs to be included, Rust does not. As such, it’s binaries will always be larger.
- seanatyc 8y agoI remember I watch a talk on youtube saying browser vendors may start make their GC runtime support GC languages (such as Golang, Java), after which we don't need a large Runtime when we consume the WASM compiled from GC languages. Probably it's far away down the road? But I was under the impression that it will soon get supported.
- steveklabnik 8y agoWasm has “add a GC” to its roadmap, but a runtime is more than just a GC. That will certainly help, but it’s not a panacea.
- grey-area 8y agoWhat Steve said! Also (and this does apply to Rust to some extent too), if you start pulling in the stdlib for your webapp then you can't avoid compiling in a lot of code (for example the fmt or net/http packages are pretty big - fmt adds around 1MB to binaries on my system here). If the stdlib for any of these popular languages could be cached or included somehow in browsers that'd be awesome, as part of the attraction of using them is having a great stdlib. It'd be great if at some point they managed to slim it down significantly as I'd really love to replace JS with Go specifically.