3 ms·
WASM is used to run native code in the Web browser without going through JavaScript. With it, it should be possible to run code at near-native performance in th
by exDM69 9y ago
WASM is used to run native code in the Web browser without going through JavaScript. With it, it should be possible to run code at near-native performance in the browser.
WASM is an intermediate representation which is output by your compiler (of your favorite language) and consumed by the browser's compiler to emit native code.
WASM is a bit similar to LLVM IR, but it's architecture independent.
Compare this to, say, LLVM and Clang. Clang (the C compiler front end) will read C code and emit LLVM IR. LLVM (the compiler backend) will read LLVM IR and emit assembly code for your CPU. With WASM, the developer will run the "front end" and distribute the WASM code over HTTP and the web browser will run the backend and turn WASM into native assembly code.
> I get that its a clever way of transpiling existing programs to JavasScript, but surely we could do that already?
No, WASM code is not JavaScript at any point. ASM.js is a predecessor to WASM that was a compiler-friendly variant of JavaScript that can be compiled to native code.
- fergie 9y agoOh I see- that makes sense.
- qaq 9y agoBut is this how it is implemented by actual browsers? if memory serves v8 is pretty much reusing most of JS VM for WASM?
- exDM69 9y agoYes, the browsers do share parts of their JavaScript execution engine with WASM. Which makes sense because WASM still needs to interact with JS. That doesn't mean it can't be fast or start quickly (or at least quicker than asm.js). From the developer's point of view that doesn't matter. You're delivering WASM and not C or JS code over to the clients.
- marcosdumay 9y agoWASM requires a much simpler VM than JS. It doesn't take most of a JS VM.