Revolution has begun Jay Phelps | @_jayphelps WebAssembly will - - PowerPoint PPT Presentation

revolution
SMART_READER_LITE
LIVE PREVIEW

Revolution has begun Jay Phelps | @_jayphelps WebAssembly will - - PowerPoint PPT Presentation

The WebAssembly Revolution has begun Jay Phelps | @_jayphelps WebAssembly will change the way we think of "web apps" Jay Phelps | @_jayphelps Jay Phelps Senior Software Engineer | @_jayphelps So... what is WebAssembly? aka wasm Jay


slide-1
SLIDE 1

WebAssembly

Jay Phelps | @_jayphelps

The

Revolution

has begun

slide-2
SLIDE 2 Jay Phelps | @_jayphelps

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

slide-3
SLIDE 3

Senior Software Engineer | @_jayphelps

Jay Phelps

slide-4
SLIDE 4 Jay Phelps | @_jayphelps

So...what is WebAssembly? aka wasm

slide-5
SLIDE 5 Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

slide-6
SLIDE 6 Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

slide-7
SLIDE 7 Jay Phelps | @_jayphelps

Fast to load and execute

slide-8
SLIDE 8 Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

slide-9
SLIDE 9 Jay Phelps | @_jayphelps

0x6a

01101010

slide-10
SLIDE 10 Jay Phelps | @_jayphelps

Intended as a compilation target

slide-11
SLIDE 11

int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } }

slide-12
SLIDE 12

int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } }

00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B

slide-13
SLIDE 13 Jay Phelps | @_jayphelps

Safe and portable

just like JavaScript is

slide-14
SLIDE 14 Jay Phelps | @_jayphelps

Is it going to kill JavaScript?

slide-15
SLIDE 15 Jay Phelps | @_jayphelps

Nope!

says browser vendors *

slide-16
SLIDE 16 Jay Phelps | @_jayphelps

*well...maybe...some day...a long time from now

(my own opinion)

slide-17
SLIDE 17 Jay Phelps | @_jayphelps

Will we compile JavaScript to WebAssembly?

slide-18
SLIDE 18 Jay Phelps | @_jayphelps

JavaScript is an extremely dynamic language

slide-19
SLIDE 19 Jay Phelps | @_jayphelps
slide-20
SLIDE 20 Jay Phelps | @_jayphelps

Compiling JavaScript to WebAssembly would run slower

What about a something JavaScript-like?

slide-21
SLIDE 21 Jay Phelps | @_jayphelps

AssemblyScript, TurboScript, ThinScript, etc

slide-22
SLIDE 22 Jay Phelps | @_jayphelps

class Coordinates { x: i64; y: i64; z: i64; constructor(x: i64, y: i64, z: i64) { this.x = x; this.y = y; this.z = z; } } export function example() { let position = new Coordinates(10, 20, 30); // later delete position; }

slide-23
SLIDE 23 Jay Phelps | @_jayphelps

WebAssembly is still missing things for broad adoption

slide-24
SLIDE 24 Jay Phelps | @_jayphelps

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

slide-25
SLIDE 25 Jay Phelps | @_jayphelps

But other languages soon!

Things like Java, OCaml, and even brand new ones

slide-26
SLIDE 26 Jay Phelps | @_jayphelps

type schoolPerson = Teacher | Director | Student(string); let greeting = (stranger) => switch stranger { | Teacher => "Hey professor!" | Director => "Hello director." | Student("Richard") => "Still here Ricky?" | Student(anyOtherName) => "Hey, " ++ anyOtherName ++ "." };

slide-27
SLIDE 27 Jay Phelps | @_jayphelps

When should I target WebAssembly right now?

slide-28
SLIDE 28 Jay Phelps | @_jayphelps

Heavily CPU-bound number computations

slide-29
SLIDE 29 Jay Phelps | @_jayphelps

Games Physics Simulation Encryption Compression Video Decoding Audio Mixing Language Detection

slide-30
SLIDE 30 Jay Phelps | @_jayphelps

Games Physics Simulation Encryption Compression Video Decoding Audio Mixing Language Detection

slide-31
SLIDE 31 Jay Phelps | @_jayphelps
slide-32
SLIDE 32 Jay Phelps | @_jayphelps

https://goo.gl/yvV92X

slide-33
SLIDE 33

https://goo.gl/YWMpdp

slide-34
SLIDE 34

asm-dom

https://goo.gl/XWBeme

slide-35
SLIDE 35 Jay Phelps | @_jayphelps

Other use cases just around the corner

slide-36
SLIDE 36 Jay Phelps | @_jayphelps

You'll likely consume compiled WebAssembly libraries even sooner

slide-37
SLIDE 37 Jay Phelps | @_jayphelps

What was that binary stuff?

slide-38
SLIDE 38

int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } }

00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B

slide-39
SLIDE 39

00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B

slide-40
SLIDE 40

00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B

slide-41
SLIDE 41

00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B

slide-42
SLIDE 42

86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01

slide-43
SLIDE 43

86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01

slide-44
SLIDE 44 Jay Phelps | @_jayphelps

Binary can be a little intimidating

slide-45
SLIDE 45 Jay Phelps | @_jayphelps

Protip: don't worry about it

(unless of course, you want to)

slide-46
SLIDE 46 Jay Phelps | @_jayphelps

Textual representation to the rescue!

slide-47
SLIDE 47 Jay Phelps | @_jayphelps

(func $factorial (param $n i32) (result i32) get_local $n i32.const 0 i32.eq if $if0 i32.const 1 return end $if0 get_local $n i32.const 1 i32.sub call $factorial get_local $n i32.mul )

slide-48
SLIDE 48 Jay Phelps | @_jayphelps

(func $factorial (param $n i32) (result i32) get_local $n i32.const 0 i32.eq if $if0 i32.const 1 return end $if0 get_local $n i32.const 1 i32.sub call $factorial get_local $n i32.mul )

slide-49
SLIDE 49 Jay Phelps | @_jayphelps

WebAssembly is a stack machine language

slide-50
SLIDE 50 Jay Phelps | @_jayphelps

stack machine: instructions on a stack

slide-51
SLIDE 51

1 + 2

slide-52
SLIDE 52

i32.add 0x6a

  • pcode

01101010

mnemonic

slide-53
SLIDE 53

stack

i32.const 1 i32.const 2 i32.add

slide-54
SLIDE 54

i32.const 1 i32.const 2 i32.add i32.const 1

stack

1

slide-55
SLIDE 55

i32.const 1 i32.const 2 i32.add i32.const 2

stack

2 1

slide-56
SLIDE 56

i32.const 1 i32.const 2 i32.add i32.add

stack

1 2

slide-57
SLIDE 57

i32.const 1 i32.const 2 i32.add

stack

3

i32.add

slide-58
SLIDE 58 Jay Phelps | @_jayphelps

call $log i32.const 1 i32.const 2 i32.add

slide-59
SLIDE 59 Jay Phelps | @_jayphelps

Compilers usually apply optimizations

real-world output is often less understandable to humans

slide-60
SLIDE 60

i32.const 1 i32.const 2 i32.add call $log

Jay Phelps | @_jayphelps
slide-61
SLIDE 61

i32.const 3 call $log

Jay Phelps | @_jayphelps
slide-62
SLIDE 62 Jay Phelps | @_jayphelps

Most tooling supports an Abstract Syntax Tree (AST)

still compiled and evaluated as a stack machine

slide-63
SLIDE 63

i32.const 1 i32.const 2 i32.add call $log

Jay Phelps | @_jayphelps
slide-64
SLIDE 64

(call $log (i32.add (i32.const 1) (i32.const 2) ) )

Jay Phelps | @_jayphelps
slide-65
SLIDE 65

(call $log (i32.add (i32.const 1) (i32.const 2) ) )

Jay Phelps | @_jayphelps

s-expressions

Yep, looks like Lisp

slide-66
SLIDE 66 Jay Phelps | @_jayphelps

Source map support is coming

slide-67
SLIDE 67 Jay Phelps | @_jayphelps

What about memory on the heap?

slide-68
SLIDE 68 Jay Phelps | @_jayphelps

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

slide-69
SLIDE 69 Jay Phelps | @_jayphelps

Accessed with instructions like i32.load and i32.store

slide-70
SLIDE 70 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

slide-71
SLIDE 71 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

1 byte

slide-72
SLIDE 72 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

slide-73
SLIDE 73 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

w a s m

slide-74
SLIDE 74 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

w a s m

slide-75
SLIDE 75 Jay Phelps | @_jayphelps

1 2 3 4 5 6 7 8 9 10

119 97 115 109

slide-76
SLIDE 76 Jay Phelps | @_jayphelps

How do I get started?

slide-77
SLIDE 77

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

slide-78
SLIDE 78 Jay Phelps | @_jayphelps

https://github.com/WebAssembly/wabt

slide-79
SLIDE 79 Jay Phelps | @_jayphelps

https://github.com/WebAssembly/binaryen

slide-80
SLIDE 80 Jay Phelps | @_jayphelps
slide-81
SLIDE 81 Jay Phelps | @_jayphelps

$ emcc main.c -s WASM=1 -o app.html

slide-82
SLIDE 82 Jay Phelps | @_jayphelps

webassembly.org

slide-83
SLIDE 83 Jay Phelps | @_jayphelps

Webpack is adding support (!!!)

They received a $125,000 grant from MOSS

slide-84
SLIDE 84 Jay Phelps | @_jayphelps

Imagine a cpp-loader / rust-loader

slide-85
SLIDE 85 Jay Phelps | @_jayphelps

What's missing?

slide-86
SLIDE 86 Jay Phelps | @_jayphelps

Direct access to Web APIs

You have call into JavaScript, right now

slide-87
SLIDE 87 Jay Phelps | @_jayphelps

Garbage collection

also necessary for better interop with JavaScript and WebIDL

slide-88
SLIDE 88 Jay Phelps | @_jayphelps

Multi-threading

slide-89
SLIDE 89 Jay Phelps | @_jayphelps

Browser support?

slide-90
SLIDE 90
slide-91
SLIDE 91 Jay Phelps | @_jayphelps

The revolution is just beginning

slide-92
SLIDE 92 Jay Phelps | @_jayphelps
slide-93
SLIDE 93 Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

slide-94
SLIDE 94 Jay Phelps | @_jayphelps

Efficient, low-level bytecode for the Web

slide-95
SLIDE 95 Jay Phelps | @_jayphelps
slide-96
SLIDE 96 Jay Phelps | @_jayphelps

Questions?

@_jayphelps

slide-97
SLIDE 97 Jay Phelps | @_jayphelps

Thanks!

@_jayphelps

slide-98
SLIDE 98 Jay Phelps | @_jayphelps
slide-99
SLIDE 99 Jay Phelps | @_jayphelps
slide-100
SLIDE 100 Jay Phelps | @_jayphelps

void log(char *); void example() { log("wasm"); }

slide-101
SLIDE 101

(module (import "env" "log" (func $log (param i32))) (memory $0 1) (data (i32.const 0) "wasm\00") (func $example (call $log (i32.const 0) ) ) )

Jay Phelps | @_jayphelps
slide-102
SLIDE 102

(module (import "env" "log" (func $log (param i32))) (memory $0 1) (func $example (call $log (i32.const 0) ) ) )

Jay Phelps | @_jayphelps

(data (i32.const 0) "wasm\00")

slide-103
SLIDE 103

(module (import "env" "log" (func $log (param i32))) (memory $0 1) (data (i32.const 0) "wasm\00") (func $example ) )

Jay Phelps | @_jayphelps

(call $log (i32.const 0) )