...but first, a story about Instruction Set Architecture and processor design.
A bytecode explicitly designed for portability, stability, compressability, security, and minimal nondeterminism.
Loading large amounts of asm.js code or using a language other than JS in the browser.
Otherwise, WASM might not be of any interest to you, yet.
A type stable subset of JavaScript that can be compiled ahead of time by existing JS engines.
The key strength of the web is safe execution of remote code.
All prior attempts taught us things like:
Sandboxing is a good idea.
We want something that is easily integrated across all browsers.
30% smaller than gzipped asm.js
Can be parsed 23x faster than large asm.js modules
Like LLVM IR, you'll be able to convert binary to text.
No need for unary plus and bitwise or operators (asm.js type hints).
Text can be shown in dev tools, source maps can show original source.
No text representation today, still working on necessary opcodes.
Not replacing them.
Two approaches:
We want to dynamically create DOM elements from a managed language and have its GC be in charge of lifetime.
Who cleans up around here?
"Supporting multiple VMs is a big infrastructural challenge ... You'll need to make sure that the different GCs can coordinate ... Otherwise you will either not have an story of object reclamation, or you'll have memory leaks ... Doing this right is hard ... See [my paper and another which found] >5% throughput regression." ~ Filip Pizlo
a contract that two binaries compiled possibly from two different compilers at two different points in time can interoperate
Need to agree upon:
That's a lot of LLVM IR, let's just use that!
wasm | llvm ir |
---|---|
portable | has architecture specific opcodes |
stable | breaking changes between versions |
small encoding | not a design goal |
fast decoding | not a design goal |
fast compiling | not a design goal |
minimal nondeterminism | nondeterminism and undefined behavior |
"... LLVM IR is a poor system for building a Platform ... LLVM isn't actually a virtual machine. It's widely acknoledged that the name 'LLVM' is a historical artifact ... LLVM IR is a compiler IR." ~ Dan Gohman
WASM is more of an ISA than a compiler IR.