96
WebAssembly Jay Phelps | @_jayphelps The Revolution has begun

The WebAssembly Revolution Has Begun

Embed Size (px)

Citation preview

Page 1: The WebAssembly Revolution Has Begun

WebAssembly

Jay Phelps | @_jayphelps

The

Revolutionhas begun

Page 2: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

WebAssembly will change the way we think of "web apps"

Page 3: The WebAssembly Revolution Has Begun

Senior Software Engineer |

@_jayphelps

Jay Phelps

Page 4: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

So...what is WebAssembly? aka wasm

Page 5: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

Page 6: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

Page 7: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Fast to load and execute

Page 8: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

Page 9: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0x6a01101010

Page 10: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Intended as a compilation target

Page 11: The WebAssembly Revolution Has Begun

intfactorial(intn){if(n==0){return1;}else{returnn*factorial(n-1);}}

Page 12: The WebAssembly Revolution Has Begun

intfactorial(intn){if(n==0){return1;}else{returnn*factorial(n-1);}}

0061736D010000000186808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B200041016B100020006C0B

Page 13: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Safe and portable just like JavaScript is

Page 14: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Is it going to kill JavaScript?

Page 15: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Nope!says browser vendors

*

Page 16: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

*well...maybe...some day...a long time from now(my own opinion)

Page 17: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Will we compile JavaScript to WebAssembly?

Page 18: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

JavaScript is an extremely dynamic language

Page 19: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Page 20: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Compiling JavaScript to WebAssembly would run slower

What about a something JavaScript-like?

Page 21: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

AssemblyScript, TurboScript, ThinScript, etc

Page 22: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

classCoordinates{x:i64;y:i64;z:i64;

constructor(x:i64,y:i64,z:i64){this.x=x;this.y=y;this.z=z;}}

exportfunctionexample(){letposition=newCoordinates(10,20,30);//laterdeleteposition;}

Page 23: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

WebAssembly is still missing things for broad adoption

Page 24: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

v1 MVP is best suited for languages like C/C++ and Rust

Page 25: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

But other languages soon!Things like Java, OCaml, and even brand new ones

Page 26: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

typeschoolPerson=Teacher|Director|Student(string);

letgreeting=(stranger)=>switchstranger{|Teacher=>"Heyprofessor!"|Director=>"Hellodirector."|Student("Richard")=>"StillhereRicky?"|Student(anyOtherName)=>"Hey,"++anyOtherName++"."};

Page 27: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

When should I target WebAssembly right now?

Page 28: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Heavily CPU-bound number computations

Page 29: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Games

Physics Simulation

Encryption

Compression

Video Decoding

Audio Mixing

Language Detection

Page 30: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Games

Physics Simulation

Encryption

Compression

Video Decoding

Audio Mixing

Language Detection

Page 31: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Page 32: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelpshttps://goo.gl/yvV92X

Demo

Page 33: The WebAssembly Revolution Has Begun

https://goo.gl/YWMpdp

Demo

Page 34: The WebAssembly Revolution Has Begun

asm-dom

https://goo.gl/XWBeme

Page 35: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Other use cases just around the corner

Page 36: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

You'll likely consume compiled WebAssembly libraries even sooner

Page 37: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

What was that binary stuff?

Page 38: The WebAssembly Revolution Has Begun

intfactorial(intn){if(n==0){return1;}else{returnn*factorial(n-1);}}

0061736D010000000186808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B200041016B100020006C0B

Page 39: The WebAssembly Revolution Has Begun

0061736D010000000186808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B200041016B100020006C0B

Page 40: The WebAssembly Revolution Has Begun

0061736D010000000186808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B200041016B100020006C0B

Page 41: The WebAssembly Revolution Has Begun

0061736D010000000186808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B200041016B100020006C0B

Page 42: The WebAssembly Revolution Has Begun

86808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B20004101

Page 43: The WebAssembly Revolution Has Begun

86808080000160017F017F0382808080000100068180808000000A9D80808000019780808000002000410046044041010F0B20004101

Page 44: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Binary can be a little intimidating

Page 45: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Protip: don't worry about it(unless of course, you want to)

Page 46: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Textual representation to the rescue!

Page 47: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

(func$factorial(param$ni32)(resulti32)get_local$ni32.const0i32.eqif$if0i32.const1returnend$if0get_local$ni32.const1i32.subcall$factorialget_local$ni32.mul)

Page 48: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

(func$factorial(param$ni32)(resulti32)get_local$ni32.const0i32.eqif$if0i32.const1returnend$if0get_local$ni32.const1i32.subcall$factorialget_local$ni32.mul)

Page 49: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

WebAssembly is a stack machine language

Page 50: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

stack machine: instructions on a stack

Page 51: The WebAssembly Revolution Has Begun

1+2

Page 52: The WebAssembly Revolution Has Begun

i32.add 0x6a

opcode

01101010

mnemonic

Page 53: The WebAssembly Revolution Has Begun

stack

i32.const1i32.const2i32.add

Page 54: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.add

i32.const1

stack

1

Page 55: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.addi32.const2

stack

2

1

Page 56: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.addi32.add

stack

1

2

Page 57: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.add

stack

3

i32.add

Page 58: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

call$log

i32.const1i32.const2i32.add

Page 59: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Compilers usually apply optimizationsreal-world output is often less understandable to humans

Page 60: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.addcall$log

Jay Phelps | @_jayphelps

Page 61: The WebAssembly Revolution Has Begun

i32.const3call$log

Jay Phelps | @_jayphelps

Page 62: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Most tooling supports an Abstract Syntax Tree (AST)still compiled and evaluated as a stack machine

Page 63: The WebAssembly Revolution Has Begun

i32.const1i32.const2i32.addcall$log

Jay Phelps | @_jayphelps

Page 64: The WebAssembly Revolution Has Begun

(call$log(i32.add(i32.const1)(i32.const2)))

Jay Phelps | @_jayphelps

Page 65: The WebAssembly Revolution Has Begun

(call$log(i32.add(i32.const1)(i32.const2)))

Jay Phelps | @_jayphelps

s-expressionsYep, looks like Lisp

Page 66: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Source map support is coming

Page 67: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

What about memory on the heap?

Page 68: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

A linear memory is a contiguous, byte-addressable range of memory

Page 69: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Accessed with instructions like i32.load and i32.store

Page 70: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

Page 71: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

1 byte

Page 72: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

Page 73: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

w a s m

Page 74: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

w a s m

Page 75: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

0 1 2 3 4 5 6 7 8 9 10

119 97 115 109

Page 76: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

How do I get started?

Page 77: The WebAssembly Revolution Has Begun

https://mbebenita.github.io/WasmExplorer/

Page 78: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

https://github.com/WebAssembly/wabt

Page 79: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

https://github.com/WebAssembly/binaryen

Page 80: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Page 81: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

$emccmain.c-sWASM=1-oapp.html

Page 82: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

webassembly.org

Page 83: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Webpack is adding support (!!!)They received a $125,000 grant from MOSS

Page 84: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Imagine a cpp-loader / rust-loader

Page 85: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

What's missing?

Page 86: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Direct access to Web APIsYou have call into JavaScript, right now

Page 87: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Garbage collectionalso necessary for better interop with JavaScript and WebIDL

Page 88: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Multi-threading

Page 89: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Browser support?

Page 90: The WebAssembly Revolution Has Begun
Page 91: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

The revolution is just beginning

Page 92: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Page 93: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

Page 94: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

Page 95: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Page 96: The WebAssembly Revolution Has Begun

Jay Phelps | @_jayphelps

Questions?

@_jayphelps