WebAssembly

Presentation by Michal Vanko

Web beyond web-applications

  • Game engines
  • VR / AR
  • Artificial inteligence
  • Image / Video processing
  • Image recognition
  • Scientific visualization and simulation

Web limits

On web we can use any language as long as it is JavaScript.

  • High level
  • No threads
  • Garbage collected
  • No binaries

Assembly

  • low-level- machine instruction
  • every architecture has a different set of instructions

asm.js

An extraordinarily optimizable, low-level subset of JavaScript

  • manual memory management
  • Type consistency
  • but still JavaScript - we can do better

WebAssembly

is a new portable, size- and load-time-efficient format suitable for compilation to the web.

  • Efficient and fast
  • Safe
  • Open and debuggable
  • Part of the open web platform

	;; simple.wasm
	(module
	(func $i (import "imports" "i") (param i32))
	(func (export "e")
		i32.const 42
		call $i))
						

Roadmap

  1. MVP (release candidate) and JS API which are implemented
  2. Tooling support
    • Editors
    • Compilers
    • Debuggers
    • Profilers
  3. Threads
  4. SIMD
  5. Zero-cost Exception Handling
  6. Feature testing

Proposals

  • Finer-grained control over memory
  • Large page support
  • More expressive control flow
  • DOM, Web API integration
  • Coroutines
  • Multiprocess support
  • Streaming Compilation

How to

Emscripten is an Open Source LLVM to JavaScript compiler.

With Emscripten you can compile code that can be translated into LLVM bitcode into JavaScript WASM


	#include <stdio.h>

	int main() {
		printf("hello, world!\n");
		return 0;
	}
						

./emcc tests/hello_world.c
						

node a.out.js
						
				
$ rustup target add wasm32-unknown-emscripten
$ echo 'fn main() { println!("Hello, Emscripten!"); }' > hello.rs
$ rustc --target=wasm32-unknown-emscripten hello.rs
$ node hello.js
						
	
fetch('simple.wasm')
	.then(response => response.arrayBuffer())
	.then(bytes => instantiate(bytes, importObject))
	.then(instance => instance.exports.e());
						

DEMO

Angry Bots

What about JavaScript?

  • JS is still evolving (ES 2017 finalized)
  • SIMD

"We’re not killing JavaScript. I don’t think it’s even possible to kill JavaScript."
Brendan Eich

Thank You