WebAssembly Isn’t Software: It’s a Computer
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).
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.”
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.
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.”