WebAssembly is not a language you should write yourself.
Its goal is to create a compilation target for other languages like C/C++, Rust, Python, etc.
5/
As it turns out, JavaScript is not the best compilation target for other languages.
There were and still are projects like asm.js, a subset of JavaScript that compilers can target.
6/
This subset of JS is so limited that ahead-of-time optimization can be applied such that the resulting code runs faster.
But this approach has its limits.
7/
WebAssembly pushes these limits and runs at near-native speed.
Because WebAssembly is basically some flavor of assembly, it's easier to create optimized code for compilers with less effort.
8/
WebAssembly also interfaces well with JavaScript and vice-versa. JavaScript is to WebAssembly what Python is to C.
You can easily call WASM functions from JavaScript to get performance gains where really necessary.
9/
3. Traits of WebAssembly
WebAssembly is designed to be:
- Efficient and fast
- Safe
- Open and debuggable
- Part of the open web platform
10/
-> Efficient and fast
WebAssembly is a flavor of assembly. This makes the binary format size- and load-time efficient.
WASM loads and runs fast.
11/
-> Safe
The WASM runtime is a memory-safe and sandboxed execution environment.
Especially in the browser, code should not be able to escape. This is one of the core principles of any browser's JavaScript runtime. The code should stay in the browser.
12/
-> Open and debuggable
Although the binary format is executed, the textual format is essential to enhance learning, improve debugging, and learn to optimize the resulting code.
A standardized text format and ways to convert between the two helps developers adopting it.
13/
-> Part of the open web platform
The main goal of WebAssebly is to run in the browser and to integrate into the existing ecosystem.
Easy interfacing between JavaScript and WASM is a core principle.
14/
4. WebAssembly outside of the browser
Although initially designed for the web, WebAssembly has long left the browser and slowly become a near-universal compilation target.
Thanks to WASI, runtimes can also interact with the OS. 👇🏻
There are still a few things that need to be worked on for WASM to become a sole alternative instead of only a sidecar for other languages.
17/
Some of those limitations are:
- No DOM support in the browser. You need to use JavaScript APIs for this
- No threading
- No garbage collection
18/
The limitations listed here are definitely being worked on, though, so those problems might soon be solved.
Until then, WebAssembly might not run multi-threaded but can still be used to speed up certain code paths or for programs that don't need threading.
19/
6. The importance of WebAssembly
"If WASM+WASI existed in 2008, we wouldn't have needed to create Docker. That's how important it is. WebAssembly on the server is the future of computing."
I've implemented nearly a hundred smart contracts with Solidity during my short blockchain career, but I'm ready to drop Solidity right now if I think about WebAssembly on the blockchain.
Interested to learn more? Let's take a look at what WASM can do for blockchains!
🧵👇🏻
1/
Before we jump in:
If you don't exactly know what WebAssembly is, this thread might help you understand the basics first. 👇🏻