WEB
ASSEMBLY
OLEKSANDR SKACHKOV @alSkachkov
ABOUT ME
• Itera’s FrontEnd Tech Lead
• WebKit contributor & JS hacker:
• Arrow function
• Async iterator & generators
• Promise.finally
• Twitter: @alSkachkov
WEB ASSEMBLY
OVERVIEW
• What was before
• WebAssembly – what is it
• WebAssembly– wasm format
• WebAssembly– what is next
HOW JS EVOLVE
• Netscape Navigator 2.0 in 1995:
• JS was born
• NPAPI – for Java plugins
• IE 3.0 - ActiveX
• Flash player initial release - 1996
• HTML5
• JiT – in modern JS engines - 2008
• Aggressive optimization algorithms and ASM.js
THE STRENGTH IS A WEAKNESS
• Easy to learn
• Executes in browser environment
• Dynamic typing
=
• LOW PERFORMANCE!
HOW BROWSER EXECUTE JS
HOW TO SOLVE BY TOOLS
• Frameworks
• Minifiers
• Optimizers – Prepack
• Rules and Hacks
TRIES TO SOLVE IN BROWSER
asm.js
• Announced in 17 June 2015
• Will be developed by major Browsers
• Developed by WebAssembly Working
Group
WebAssembly - Game Changer
What is WebAssembly (aka WASM)?
WebAssembly is build target
Will WebAssembly replace JavaScript?
Will WebAssembly replace JavaScript?
Not now 
but WebAssembly will transform web
safe, portable, low-level code format designed for efficient execution
and compact representation
https://webassembly.github.io/spec/intro
safe, portable, low-level code format designed for efficient execution
and compact representation
https://webassembly.github.io/spec/intro
fast to load
binary format
fast to load
fast to load
fast to load
fast to parse
fast to parse
S - expression
fast to parse
no ambiguous syntax
fast to parse
no ambiguous syntax
binary format
fast to parse
no ambiguous syntax
Only 2 phase before execution: decode, validation
binary format
safe, portable, low-level code format designed for efficient execution
and compact representation
https://webassembly.github.io/spec/intro
fast to execute
fast to execute
close to browser IR
fast to execute
1.2x speed of the native code
close to browser IR
HOW BROWSER EXECUTE WASM
JS
WASM
safe, portable, low-level code format designed for efficient execution
and compact representation
https://webassembly.github.io/spec/intro
SAFE
• Limit set of operation
• Controlled operations with memory
• Using import table
MEMORY MODEL
• 8-bit bytes
• Linear memory
• Simulates the heap
• Used ArrayBuffer
• Memory.import can be used by several WASM modules
HOW TO WORK IN BROWSER
• WebAssembly object
• No access to web API or DOM
• Integration with JavaScript
INTERACTION WITH JAVASCRIPT
We can use JS function in WASM and WASM function in JS
INTERACTION WITH JAVASCRIPT
We can use JS function in WASM and WASM function in JS
INTERACTION WITH JAVASCRIPT
We can use JS function in WASM and WASM function in JS
WASM Binary format demystification
fast to load
WASM Code explorer
https://wasdk.github.io/wasmcodeexplorer/
WASM Code explorer
https://wasdk.github.io/wasmcodeexplorer/
Binary encoding
https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
WASM Code explorer
https://wasdk.github.io/wasmcodeexplorer/
fast to load
fast to load
fast to load
fast to load
fast to load
USAGE SCENARIOS
• Write faster version of the specific application
• Using existing C libraries in browser
• Reuse algorithm from service side
• Distribute whole application as WebAsm
Ethereum flavored WebAssembly
BUILD TARGET FOR
• C/C++
• TypeScript/TurboScript
• Rust
• C#
• Go
VM
• Blazor: NET code in the browser via the Mono runtime, which itself
is compiled to WebAssembly and asm.js (Steve Sanderson)
• TeaVM: transpiler of Java bytecode, to emit JavaScript and
WebAssembly (Java, Kotlin, Scala) (Alexey Andreev)
• Ocamlrun: OCaml bytecode interpreter for WebAssembly
(Sebastian Markbåge)
CAN WE USE WEBASSEMBLY?
Global support 65% + nodejs >7.2.X
Yes we can
FUTURE
• GC – garbage collector
• Threads
• Exception handling
• Tools
• SIMD - single instruction, multiple data
• More proposals coming
EXAMLES
• Video editor https://d2jta7o2zej4pf.cloudfront.net/
• Game: http://webassembly.org/demo/Tanks/
• Garden for Mozilla: https://s3.amazonaws.com/mozilla-
games/ZenGarden/EpicZenGarden.html
• WebSight: https://websightjs.com/
RESOURCES
• Twitter @WasmWeekly - WebAssemblyWeekly
• Site http://webassembly.org/
• Github https://github.com/WebAssembly/

WebAssembly overview. KievJS meetup

Editor's Notes

  • #5 In Was created in 1995 by Brendan Eich in NestScape Named by founder of the  a name chosen by Marc Andreessen, founder of Netscape Netscape Plugin Application Programming Interface – allow integrate different plugin to work with different mime/types (cross-platform plugin architecture used by some Web browser) ActiveX
  • #9 ‎Native Client (NaCl) · ‎ Portable Native Client (PNaCl)  Tried by each browser No general format
  • #58 MVP No SPEC More features are coming
  • #59 Thread https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md