WebAssembly Isn’t Software: It’s a Computer

WebAssembly’s computational potential has garnered significant attention, and it may take quite some time, possibly a couple of years, for its true capabilities to be fully realized as these challenges are resolved. One of these challenges involves ensuring that WebAssembly modules can support all programming languages, although currently, it is predominantly limited to a few, such as Rust, C++, Python and JavaScript. Other languages still face hurdles, but even Rust and C++ as well as Python have their issues when the idea is for developers to write code and deploy once and everywhere to numerous devices and environments, all compatible of course.
But what is WebAssembly meant to achieve? The phrase “deploy once, deploy anywhere” has often been used, although it might be more accurate to say that you can write your code once and deploy it on any CPU or device simultaneously with minimal to no configuration required. Think of it, in some ways, as a highly efficient compiler (although some will likely passionately disagree).
Standard Definition
Citing the standard definition, WebAssembly is a binary instruction format for a stack-based virtual machine, Luke Wagner, a distinguished engineer for edge cloud platform provider Fastly, said during his talk at WasmCon 2023. “Wasm’s design is a portable compilation target for programming languages. I think the operative phrase here is ‘compilation target,”‘ which means we can take our variety of source languages,” Wagner said. “In addition to being able to compile them to all the different native instruction sets, we can compile them to WebAssembly. Then, we can take that WASM and send it to a browser or WASM engine of some sort, which will internally compile it to the actual instruction set it’s running on. What this buys us is portability, determinism if we need it, control flow integrity, and subprocess sandboxing.”
Beyond its definition, it’s necessary to look at what WebAssembly can do in the real world. “So, what are we doing with all these cool powers? Well, today, in browsers, popular use cases deport a large code base, especially C++,” Wagner said. Examples include Unity, AutoCAD and Photoshop. Also, offloading compute-intensive subtasks from JavaScript to Wasm, with examples including codecs, compression, inference, encryption and filters, Wagner said.
“Outside a browser, it’s popular to embed Wasm in your existing system to bring your guest code closer to your system. An example of this is a browser that has a lot of code that’s not in JavaScript,” Wagner said. “Lastly, people are using Wasm to explore alternative models of distributed computing, like serverless, distributed actors, record and replay, and edge computing, similar to what we’re doing at Fastly.”
The use cases for WebAssembly are expanding, but there is ongoing work and project progress. When the day arrives, for example, when the component structure is more standardized, the deployment across various devices and environments will become more achievable. Hopefully, this can be achieved in the near future, perhaps within a year and a half or two years.
Like a Computer?
During a recent conversation with Liam Crilly, senior director of product management at NGINX, he likened WebAssembly to a computer in a conceptual sense. Although WebAssembly doesn’t directly run on physical devices, it has the potential to operate across a network of devices used for data exchange and deployment, employing WebAssembly modules, as explained by Crilly.
“WebAssembly allows us to rethink the abstractions we need,” Crilly stated. “As a society, it enables us to take the next step forward rather than being continually anchored to the initial primitives we used to describe storage and compute. That’s why I mentioned it in the context of Kubernetes, as it still carries some of that baggage.”
Indeed, WebAssembly can be thought of as a new type of computer. It possesses an instruction set, similar to a CPU, from which the “assembly” part derives. When you examine sample code, it closely resembles that, provided it’s made human-readable. This simple computer is capable of performing anything a traditional computer can, which, as we know, is quite extensive. What’s significant is that this new, straightforward instruction set becomes a compilation target for all programming languages. Essentially, any high-level programming language can be compiled not just to the CPU instruction set of specific hardware but also to the WebAssembly instruction set.
Furthermore, WebAssembly can be seen as a powerful compiler target, as Crilly explained: “What’s fascinating about WebAssembly is that it provides the advantages of a compiler, enabling you to take a high-level language and generate well-optimized instruction set code.” However, because WebAssembly functions as an abstracted computer, it necessitates a virtual machine or runtime to take this instruction set and execute it on the hardware. While this might initially seem like an additional abstraction layer, it’s actually quite ingenious. With WebAssembly, it’s possible to construct a runtime for any hardware, eliminating the need for developers and operators to concern themselves with specific hardware details, Crilly said.
Crilly further emphasized, “If I have a WebAssembly module that I’ve compiled to this instruction set, I reap the benefits of compiler optimizations as well as the insights gained from over a decade of JavaScript experience in the browser, which includes just-in-time (JIT) optimizations during runtime as I convert the bytecode from this instruction set into CPU instructions. This additional layer of optimization, akin to JIT compilers and browser runtimes, provides near-native compute performance. Therefore, there’s minimal downside to this abstraction layer.”
Computer within a Computer
Taking the concept of thinking of WebAssembly as a computer further, Torsten Volk, an analyst for Enterprise Management Associates (EMA), said he would describe WASM as a “computer within a computer.”
“Instead of providing direct access to CPU, RAM, storage and networking hardware, it provides apps with access to simplified generic versions of these resources,” Volk said. “It does that by translating the instructions that come from the bytecode of apps that were compiled for WASM into bytecode that directly talks to the instruction sets of CPUs, RAM, and disk. Once this translation layer works universally for most types of applications, you could actually describe the WASM runtime as a new type of computer. ”
At the end of the day, WebAssembly is “the third wave of how we think about operating systems and hardware,” Matt Butcher, co-founder and CEO of Fermyon Technologies, told The New Stack. “Virtual Machines broke us out of thinking of operating systems as having a one-to-one relationship with hardware. We can run lots of OSes on a single piece of hardware, while containers furthered this story by allowing us to safely (and in a multitenant way) run lots of discrete filesystems that share one kernel,” Butcher said. “Wasm is the third wave: The application has no direct dependency on the host operating system. It simply declares what it needs, and the host runtime can fulfill specifically those needs. Finally, the developer does not need to know anything about the target environment’s OS or architecture.”