Portable binary format for web
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.
- wasm became a w3c approved specification in 2019
wasmis 4th language to run natively in browser alongside
- Compiler LLVM supported languague to wasm using Emscripten
- WebAssembly is usually either ahead-of-time (AOT) or just-in-time (JIT) compiled
# 🐵 History
|2011||precursor technology||Google Native Client|
|2015||1st demonstration||executing Unity's Angry Bots in Firefox,Chrome,Edge|
|2019||Became w3c recommendation (REC)||Web client now supports 4 language. |
|Future||plans to support multithreading and garbage collection||support |
Old browser support
In web development, a polyfill is code that implements a feature on web browsers that do not support the feature.
# 🏎 Performance
20% slower than native code execution
PHP 8 will come with JIT compiler
So, what performance depends on
- I/O, images, databases, HTTP, rendering, fonts, frameworks, network
If you ship slightly smaller images, your improvments are far bigger than any compiler optimization you could make.
JSis dynamically types,
C++is statically typed
- faster to prototype but little more work for compiler to keep up with dynamic types
property lookup is all over js
console.log()log property on console Object
- Property Chain
implement same algorithm in both languages (prime #) and then plott for #inputs
jsis maybe 2X times as slower as
TurboFan(precursor CrankShell) as its optimizing compiler introduced in 2017
- in js if you have a function but its bever used, its not even compiled
- if a fn is executed multiple times, its send to optimizing compiler
- using some heuristics and speculation techniques
- is turned on when function is hot. Optimization only happens on hot functions
We can turn off the optimizing compiler in node using
- run everything with baseline compiler
# How to write wasm?
# ❓ Questions
- How to compile your code js to wasm?
- How to debug it from devtools?
- HOw to write wasm?