WebAssembly, in truth, neither is strictly web nor assembly. Then what is it? We will try to answer this question in this short blog series about WebAssembly.
What is WebAssembly?
In looking for an answer, a good place to start is providing a definition from the WebAssembly homepage: "WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. WebAssembly is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications".
But it’s important to emphasize that you can’t just run your code through a compiler and have it produced WebAssembly in a way so that it magically works. There should be some modifications done on the code.
Although it can be written and viewed in a human-readable format (wat file), WebAssembly is not meant to be a programming language that humans write directly, rather a set of binary instructions that is generated by a compiler from some higher-level programming language. Binary representation is what is actually delivered to the browser.
How does Wasm work?
As we said in the WebAssembly definition, it’s a binary instruction format executed in a stack-based virtual machine. If you are a Java developer, this concept may sound familiar to you because Java works in the same way. Java files are compiled into bytecode (.class files) which is executed by Java Virtual Machine (JVM).
JVM is a stack-based virtual machine.
WebAssembly follows exactly the same concept except it runs inside the browser.
There are many different methods for loading the Wasm module which you can check out on WebAssembly API page.
Video (hasn’t) killed the radio star
In this blog post we gave a short overview of WebAssembly, how it works and what it brings to the web. We saw WebAssembly development workflow and its great efficiency and speed. With WebAssembly we can take existing libraries, games, and command-line tools written in other programming languages and run them on the web at almost native speed.
For more details on WebAssembly, I highly recommend checking out the Awesome Wasm git repository where you can find tones of interesting things about WebAssembly.
WebAssembly in action
On the links below you can see some real-world examples of WebAssembly in action: