How WebAssembly May Reinvent How We Write and Ship Code on the Web
Milham gave an overview talk called “What’s a WASM?” at the most recent Node.js Interactive conference, and his enthusiasm for the language was inspirational. The New Stack caught up with Milham recently to talk about his feeling that WebAssembly/WASM has the potential to “completely reinvent how we write and ship code on the web” — and ways to get started learning.
So, then, what’s a WASM?
First, a disclaimer: I’m not anyone important; I didn’t design WebAssembly or anything like that. I just think it’s awesome and could be a really big deal for how we code on the web. I actually wish I knew more about the history of WebAssembly — the best source for this is maybe Brendan Eich’s Twitter feed. It also seems to most directly draw its origins from asm.js. I’m sure other projects like Google’s PNaCl probably influenced its design as well. Like everything else related to the web, there’s a sense that these amazing things have somehow crawled from a primordial ooze.
I like the definition from webassembly.org, which says simply that “WebAssembly, or WASM, is a new, portable, size- and load-efficient format suitable for compilation to the web.”
Binary encoded assembly is a really good description of WebAssembly language. Don’t expect anything fancy like a for-loop — it’s a lot lower level than that. It’s an efficient and fast stack machine that is safe, open and debuggable. It’s web tech! It is not some separate thing; this upholds all the values of the web. And this is REAL. A lot of people don’t realize this but WebAssembly is in your browser now. It’s in Firefox, it’s in Chrome. It’s in Safari, in Edge. And it is in Node.js. Download the latest version of node, type webassembly in, hit enter, you’re going to see there is an object there.
What intrigued you personally about WebAssembly to the point where you decided to sit down and learn the language yourself?
So, as an engineer, I’m always studying new technology. If you want to stay relevant, you need to keep that mindset of always learning. WebAssembly, in particular, interested me because it promises speed but also predictable performance — those two features are very attractive to game developers.
WebAssembly has a lot more to offer beyond this, too, but this is what personally excites me the most.
Do you have any current favorite examples of places where WASM is in use?
WebAssembly is still really new, but it’s supported in all major browsers at this point and we are seeing interesting use cases starting to crop up. Mozilla is using it with Rust to parse source maps, and several game engines like Unity and Unreal are using it as a compilation target. I think we’re soon going to start seeing it in use in lots of performance-critical areas.
The big question is, how does this make my life as a developer better, or easier?
WebAssembly code is fast to execute, quick to download and has a few tricks up its sleeve like being able to be compiled while it downloads. In short, WebAssembly makes the web a more performant platform. Ultimately, what’s good for the web is going to be good for web developers.
So if one the most exciting parts of WASM is allowing just about any language to target the browser, or even node.js, what are some potential ways this power could be harnessed going forward?
One of the coolest things about WebAssembly is that it is a compilation target and I think we’ll eventually see pretty much everything compile to it. Even though it’s missing features like garbage collection, we’re already seeing lots of languages advertising experimental support for it.
What is the best way for someone interested in WA to start learning/using?
Start with [Matteo Basso’s repository of WASM resources]. This repository is pure gold. It’s just a huge list of WebAssembly resources. To get hands-on experience, I’d recommend just playing around with it.
Then, WasmFiddle is really cool to experiment with without having to set up a toolchain. You just type c code in a browser and it’ll handle the compilation to WebAssembly for you.
If you want to hand code then Wabt (pronounced wabbit) is a great resource. That’s what I used to write my first WebAssembly module.
Be forewarned though, it’s kind of stone age way to write code. Don’t forget that WebAssembly is a compilation target, so you can see if your preferred tooling has support for it and try it that way. My personal favorite right now is Rust [to] WebAssembly. Really cool stuff happening there. High-level tools like Unity are adding WebAssembly support. Using something like that you can reap the benefits of WebAssembly without understanding the underlying technology at all.