Do things faster & better
with WebAssembly
@sendilkumarn
Slide 2
Slide 2 text
Sendil Kumar
• Full stack developer @Xebialabs
• Core dev team member @JHipster
• Team member @webpack
• Part of rust-wasm Working Group
• Big open source lover & enthusiast
Slide 3
Slide 3 text
@sendilkumarn
You can reach me at
Slide 4
Slide 4 text
Fullstack devs ?
Slide 5
Slide 5 text
C / C++ devs ?
Slide 6
Slide 6 text
Rust devs ?
Slide 7
Slide 7 text
Faster
More
control
Safety
Types
Closer to
machine
Slide 8
Slide 8 text
! JS devs ?
Slide 9
Slide 9 text
What you do to increase
the Performance of your
App ?
Slide 10
Slide 10 text
Minify
Async & Defer
Reduce dom
manipulation
Profile
JS Engine based
optimisations
Immutability
Type system
Code splitting
Service worker
Slide 11
Slide 11 text
Let us do a
performance question
Slide 12
Slide 12 text
Which has higher
performance?
function test() {
let arr = [];
arr.push(1);
arr.push(2);
arr.push(3);
}
function test() {
let arr = new Array(3);
arr.push(1);
arr.push(2);
arr.push(3);
}
Slide 13
Slide 13 text
This has higher
performance
function test() {
let arr = [];
arr.push(1);
arr.push(2);
arr.push(3);
}
function test() {
let arr = new Array(3);
arr.push(1);
arr.push(2);
arr.push(3);
}
Slide 14
Slide 14 text
But why ?
Packed & Holey Array
https://v8project.blogspot.nl/2017/09/elements-kinds-in-v8.html
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
Uncertainties
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
Most of the profiling, needs you to know
more about the internals of JS engine.
Slide 19
Slide 19 text
Optional
Arguments
Packed/Holey
Array
Monomorphisation
Micro-
benchmarking
Engine based
tunings
Known engine
shortcomings
Time-
consuming
Slide 20
Slide 20 text
⚙ Maintainability ⚙
Slide 21
Slide 21 text
Tradeoff between
Uncertainty &
Performance
Slide 22
Slide 22 text
How better will it be to have
the consistency & speed of
native code in browsers?
Slide 23
Slide 23 text
WebAssembly
Binary encoded - Stack machine
Slide 24
Slide 24 text
In other words, you can compile
your native code and make
them run in your browser.
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
Fast & Efficient
Slide 27
Slide 27 text
Fast & Efficient
Safe
Slide 28
Slide 28 text
Fast & Efficient
Safe
Debuggable
Slide 29
Slide 29 text
Fast & Efficient
Safe
Debuggable
Open web platform
Slide 30
Slide 30 text
“WebAssembly is not a
replacement of JAVASCRIPT”
integrating well and being symbiotic
WASM
MEMORY
GLOBAL
START (start $start_function)
The first function to be loaded in the module
(global type mutability expr)
(memory init-size max-size(opt))
Slide 48
Slide 48 text
WASM
TABLE
ELEMENT
DATA Data -> linear array of memory indexes
GC references, raw OS handles, or native pointers
Allows module to initialise the elements
Using instantiate streaming…
⚠Few browsers yet to support
Slide 62
Slide 62 text
Using instantiate streaming…
WebAssembly.instantiateStreaming(
(fetch(‘test.wasm’), importObj)
.then(result =>
result.instance.exports.add_one()
);
⚠Few browsers yet to support
Slide 63
Slide 63 text
Streaming compilation
speeds up the wasm
performance by 10-15 times
Streaming compilation will be coming to JS…
Slide 64
Slide 64 text
ESM spec for WASM
⚠Still in very early stages, and will be implemented