Web Assembly
A lightweight introduction
About me
Outline
● What is WA
● Why WA
● Chasing performance
● Feature
● Demo
● The future
● Q&A
What is Web Assembly?
WebAssembly, or wasm, is a new portable, size-
and load-time-efficient format suitable for
compilation to the web.
It’s a virtual machine for the web!
Why Web Assembly?
because of Javascript
● Freedom to choose a different language
○ Run CC++ codebase in a browser
● Performance
○ Dynamic Typed language
○ engine optimization
○ JS bottlneck
Why WA
Chasing performance
● engine
○ parse source
○ create AST
○ create machine code
● code optimization - turboFan
○ looking for slow function
○ optimization
○ code analisys is CPU intensive
Chasing performance - Javascript
Javascript V8 Engine
function add(a, b) {
return a + b;
}
Javascript addition operator semantic
Javascript addition operator semantic
Javascript addition operator semantic
Javascript addition operator semantic
Javascript addition operator semantic
● plugins
○ Flash
○ Java
● Google Native Client (NaCl)
○ Open Source
○ Run native code in a sandbox
● asm.js
○ compiler target
○ c++ to Javascript (subset) fast native code
○ different performance over different engine
Chasing performance
Feature
Feature - Goal
● Portable
● Extendible
● Integrated with Web Standard
● Using existing tools
Feature
● Compile target
● Internal browser VM
● Cross browser support
● Javascript API
● Version 1 (MVP)
Module:
distributable, loadable, and executable unit of code
Feature - Module
● import
● export
● start
● global
● memory
● data
● table
● elements
● functions
Feature - Module
● index spaces
○ function
○ table
○ global
○ linear memory
Feature - Module
● Binary encoding
○ Efficient and fast
○ Stack based VM
○ Native speed
● Text format
○ LISP like
Feature - Javascript API
● Integrated with Web Platform
○ WebAPIs via JS
○ JS interoperability
Feature - Type
● types
○ void
○ i32
○ i64
○ f32
○ f64
Feature - Memory
● linear memory
○ untyped array of bytes
○ 64KiB page size
● grow_memory operator
Feature - Memory
● operators
○ load
○ store
● effective address
○ sum of address operand and an
offset operand
● out-of-bound check
○ out-of-bound trap
Feature - Security
● sandbox
○ using only API
● security policies of its
embedding
● function declared at load time
Feature - Security
● control flow integrity (CFI)
○ Function call
○ Indirect function call
○ returns
● By design
Feature - Tools
It’s time for a demo!
Demo
Demo
● http://webassembly.org/demo/
● https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.ht
ml
What’s next?
● Garbage collector
○ Support new languages
● Multithread support
● wasm64
● Exception handling
What’s next?
Questions?
valeriocomo
Thank you!|
@valeriocomo
valeriocomo@gmail.com
http://www.valeriocomo.com
References
● http://www.webassemly.org
● https://en.wikipedia.org/wiki/Type_system
● http://webassembly.org/docs/semantics/
● http://webassembly.org/docs/modules/
● http://webassembly.org/docs/mvp/
● http://webassembly.org/docs/future-features/
● https://youtu.be/6v4E6oksar0
● https://youtu.be/DKHuEkmsx3M
References
● https://rsms.me/wasm-intro

Web Assembly