SlideShare a Scribd company logo
WebAssembly for the rest of us
Mozilla Dev Roadshow, Düsseldorf
Jan-Erik Rediger — @badboy_ | 2017-05-14
Amsterdam 16 - 17 May
2017
{ WebAssembly for the rest of us
Jan-Erik Rediger — @badboy_
Zen Garden
(WebAssembly Demo)
Jan-Erik Rediger
@badboy_
Organizer
Work / Tech Speaker
WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017
WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017
What is WebAssembly?
Binary executable format for the web
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 01 6d 0b
What is WebAssembly?
General purpose virtual architecture
get_local $0
i32.const 2
i32.add
i32.const 42
i32.eq
return
What is WebAssembly?
Compiler target
Compiler
What is WebAssembly?
Open standard
WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017
What is WebAssembly not?
What is WebAssembly not?
Replacement for JavaScript
What is WebAssembly not?
Replacement for JavaScript
Programming Language
What is WebAssembly not?
Replacement for JavaScript
Programming Language
A good target for every dynamic language
Why WebAssembly?
1995
2008
2013: asm.js
Research project
Type Annotations in JavaScript
function add(x, y) {
return (x + y);
}
Type Annotations in JavaScript
function add(x, y) {
* x = x|0; // <- parameter type annotation
y = y|0;
* return (x + y) | 0;
} // ^- return type annotation
Linear memory access
from "Introduction to WebAssembly" by Rasmus Andersson
Linear memory access
size_t strlen(char *ptr) {
char *curr = ptr;
while (*curr != 0) {
curr++;
}
return (curr - ptr);
}
Linear memory access
function strlen(ptr) {
ptr = ptr|0;
var curr = 0;
curr = ptr;
while (HEAP8[curr]|0 != 0) {
curr = (curr + 1)|0;
}
return (curr - ptr)|0;
}
Linear memory access
function strlen(ptr) {
ptr = ptr|0;
var curr = 0;
curr = ptr;
* while (HEAP8[curr]|0 != 0) {
curr = (curr + 1)|0;
}
return (curr - ptr)|0;
}
Why not use asm.js?
Pros:
"It's just JavaScript"
It's fast
Why not use asm.js?
Pros:
"It's just JavaScript"
It's fast
Cons:
Informal spec
No speed guarantuees
Hard to extend
No 64-bit integers
Why not use asm.js?
Why WebAssembly?
Why WebAssembly?
Smaller than asm.js
Why WebAssembly?
Smaller than asm.js
Faster parsing
Why WebAssembly?
Smaller than asm.js
Faster parsing
Freedom to extend
Why WebAssembly?
Smaller than asm.js
Faster parsing
Freedom to extend
Formal specification
Use cases
Game Engines {
Multimedia
Performance
Libraries
64-bit math
Tanks Demo
Zen Garden
Use cases
Game Engines
Multimedia {
Performance
Libraries
64-bit math
Image/Video editing
Image recognition
Live video augmentation
CAD applications
Use cases
Game Engines
Multimedia
Performance {
Libraries
64-bit math
Password store
Encryption
Compression
Platform simulation
Use cases
Game Engines
Multimedia
Performance
Libraries {
64-bit math
OpenCV
Box2D
LibSass
DICOM (Medical Image File
Format)
Use cases
Game Engines
Multimedia
Performance
Libraries
64-bit math {
MAME
SHA512
Physic calculations
How to use it
Use the compiler!
Compiler
open source LLVM-based compiler from C and C++* to JavaScript
* and Rust
open source LLVM-based compiler from C and C++* to asm.js
* and Rust
open source LLVM-based compiler from C and C++* to WebAssembly
* and Rust
Some C code
int half(int x)
{
return x / 2;
}
Compile it
clang -O3 
-c half.c -o half.o
Compile it
emcc -O3 
-s WASM=1 -s SIDE_MODULE=1 
half.c -o half.wasm
Wasm (binary representation)
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 01 6d 0b
|.asm...........`|
|................|
|...p............|
|..............me|
|mory...half.....|
|.......... .A.m.|
Wasm (binary representation)
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 01 6d 0b
|.asm...........`|
|................|
|...p............|
|..............me|
|mory...half.....|
|.......... .A.m.|
Wasm (binary representation)
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 01 6d 0b
|.asm...........`|
|................|
|...p............|
|..............me|
|mory...half.....|
|.......... .A.m.|
Wasm (binary representation)
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 01 6d 0b
|.asm...........`|
|................|
|...p............|
|..............me|
|mory...half.....|
|.......... .A.m.|
Wasm (binary representation)
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 04 84 80 80
80 00 01 70 00 00 05 83 80 80 80 00 01 00 01 06
81 80 80 80 00 00 07 91 80 80 80 00 02 06 6d 65
6d 6f 72 79 02 00 04 68 61 6c 66 00 00 0a 8d 80
80 80 00 01 87 80 80 80 00 00 20 00 41 02 6d 0b
|.asm...........`|
|................|
|...p............|
|..............me|
|mory...half.....|
|.......... .A.m.|
Wast (text representation)
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "half" (func $half))
(func $half (param $0 i32) (result i32)
(i32.div_s
(get_local $0)
(i32.const 2)
)
)
)
Wast (text representation)
(module
* (table 0 anyfunc)
* (memory $0 1)
* (export "memory" (memory $0))
* (export "half" (func $half))
(func $half (param $0 i32) (result i32)
(i32.div_s
(get_local $0)
(i32.const 2)
)
)
)
Wast (text representation)
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
* (export "half" (func $half))
(func $half (param $0 i32) (result i32)
(i32.div_s
(get_local $0)
(i32.const 2)
)
)
)
Wast (text representation)
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "half" (func $half))
(func $half (param $0 i32) (result i32)
* (i32.div_s
* (get_local $0)
* (i32.const 2)
)
)
)
JavaScript API
fetch('half.wasm')
.then(data => data.arrayBuffer())
.then(buf => WebAssembly.compile(buf))
.then(mod => WebAssembly.instantiate(mod))
.then(ins => alert(ins.exports.half(128)))
Run code
Available in Rust!
rustup target add wasm32-unknown-emscripten
cargo build --target wasm32-unknown-emscripten
Check out hellorust.com/wasm
More tooling: WasmExplorer
More tooling: Wasm Fiddle
WebAssembly's future
WebAssembly's future
Threads
WebAssembly's future
Threads
SIMD
WebAssembly's future
Threads
SIMD
Feature-testing
WebAssembly's future
Threads
SIMD
Feature-testing
GC/DOM/Web API integration
WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017
{ If you're a Native developer,
the Web is just a compiler
target away.
by @callahad
{ If you're a Web developer,
you can leverage the
enormous world of native
libraries.
by @callahad
{ Both worlds have to learn
from each other to make the
most of this.
by @callahad
Want to know more?
Want to help?
webassembly.org
Want to play around using Rust?
hellorust.com/wasm
Amsterdam 16 - 17 May
2017
{ Thank you!
Jan-Erik Rediger — @badboy_
Sources & Credit
Code File: Pham Thi Dieu Linh, The Noun Project, CC BY 3.0
Gears: Gregor Cresnar, The Noun Project, CC BY 3.0
Linear Memory: Introduction to WebAssembly
Last quotes: @callahad

More Related Content

PDF
Mimstris: Building an arcade puzzle game in React / Redux
PDF
Animalsmath
PPTX
Examining Malware with Python
PDF
WebAssembly. Neither Web Nor Assembly, All Revolutionary
PDF
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
PPTX
Introduction to debugging linux applications
PPTX
Assembly Language Tutorials for Windows - 03 Assembly Language Programming
PDF
The walking 0xDEAD
Mimstris: Building an arcade puzzle game in React / Redux
Animalsmath
Examining Malware with Python
WebAssembly. Neither Web Nor Assembly, All Revolutionary
hashdays 2011: Ange Albertini - Such a weird processor - messing with x86 opc...
Introduction to debugging linux applications
Assembly Language Tutorials for Windows - 03 Assembly Language Programming
The walking 0xDEAD

Similar to WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017 (20)

PPT
Wk1to4
PDF
The WebAssembly Revolution Has Begun
ODP
The forgotten art of assembly
PDF
No more dumb hex!
PDF
Wasm intro
PDF
Introduction to assembler_programming_boston_2
PPTX
Co&amp;al lecture-05
PDF
Build Your Own WebAssembly Compiler
PDF
A world to win: WebAssembly for the rest of us
PPTX
WebAssembly: In a Nutshell
PPT
Chapter Eight(3)
PPT
class04_x86assembly.ppt hy there u need be
PPT
Assembler
PPT
Assembler
PPTX
PPT
10 instruction sets characteristics
PPT
Instruction Set Architecture
PPT
Material com Conceitos de Assembler Mainframe
Wk1to4
The WebAssembly Revolution Has Begun
The forgotten art of assembly
No more dumb hex!
Wasm intro
Introduction to assembler_programming_boston_2
Co&amp;al lecture-05
Build Your Own WebAssembly Compiler
A world to win: WebAssembly for the rest of us
WebAssembly: In a Nutshell
Chapter Eight(3)
class04_x86assembly.ppt hy there u need be
Assembler
Assembler
10 instruction sets characteristics
Instruction Set Architecture
Material com Conceitos de Assembler Mainframe
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
cuic standard and advanced reporting.pdf
PPTX
Machine Learning_overview_presentation.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A comparative analysis of optical character recognition models for extracting...
cuic standard and advanced reporting.pdf
Machine Learning_overview_presentation.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx

WebAssembly for the rest of us - Jan-Erik Rediger - Codemotion Amsterdam 2017