SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
WebAssembly:
the browser VM we were
waiting for
Boyan Mihaylov
@bmihaylov
Birth of JavaScript
@bmihaylov | Voxxed Days Thessaloniki 2016 2
1995
Created by Brendan Eich
in 10 days and released
in Netscape Navigator 2.0
Microsoft hits back
@bmihaylov | Voxxed Days Thessaloniki 2016 4
19961995
Microsoft releases
JScript in IE3
Becoming a standard
@bmihaylov | Voxxed Days Thessaloniki 2016 5
The first edition of
ECMA-262 is released
199719961995
photo: engineering.wix.com
2007-2008199719961995
6@bmihaylov | Voxxed Days Thessaloniki 2016
@bmihaylov | Voxxed Days Thessaloniki 2016 7
The jQuery era
JavaScript goes server-side
@bmihaylov | Voxxed Days Thessaloniki 2016 8
Mobile apps
@bmihaylov | Voxxed Days Thessaloniki 2016 9
JavaScript conquers the world
@bmihaylov | Voxxed Days Thessaloniki 2016 10
source: https://www.codementor.io/learn-programming/beginner-programming-language-job-salary-community
102.3K
280.4K
431.7K
444.4K
512.1K
791.9K
953.9K
962.4K
1,699.7K
1,964.5K
Swift
Objective-C
C#
C
C++
PHP
Python
Ruby
Java
JavaScript
Total GitHub Projects
(as of February 2016)
20.9K
31.6K
50.5K
67.7K
90.3K
112.0K
117.9K
125.1K
191.9K
200.1K
Swift
Ruby
SQL
C
C++
Python
C#
PHP
Java
JavaScript
StackOverflow Tag Followers
(as of February 2016)
@bmihaylov | Voxxed Days Thessaloniki 2016 11
The new Web
We compile to JavaScript
@bmihaylov | Voxxed Days Thessaloniki 2016 12
New compilation source
@bmihaylov | Voxxed Days Thessaloniki 2016 13
Issues with JavaScript
Just-In-Time compilation
Types are inferred on runtime
Variables can change types
Automated garbage collection
@bmihaylov | Voxxed Days Thessaloniki 2016 14
Meet asm.js
@bmihaylov | Voxxed Days Thessaloniki 2016 15
Started by Mozilla in 2013
It defines a subset of JavaScript
Avoids potential slowdowns in code
e.g., no variables with mixed type
It does only low-level assembly-like computation
exactly what compiled C/C++ needs
@bmihaylov | Voxxed Days Thessaloniki 2016 16
C/C++ Emscripten
.js
.js + .html
Node.js
Web Browser
Hello, world
@bmihaylov | Voxxed Days Thessaloniki 2016 17
…
function _main() {
var $0 = 0, $vararg_buffer = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 16|0;
if ((STACKTOP|0) >= (STACK_MAX|0))
abort();
$vararg_buffer = sp; $0 = 0;
(_printf(672,$vararg_buffer)|0);
STACKTOP = sp;
return 0;
}
…
#include<stdio.h>
int main() {
printf(“Hello, Thessaloniki“);;
return 0;
}
C program (1KB) asm.js output (479KB)
asm.js example
@bmihaylov | Codemotion Milan 2015 18
asm.js module definition Usage in JavaScript
function CircleModule(stdlib, foreign, heap) {
"use asm";
var pi = +stdlib.Math.PI;
function area(r) {
r = r | 0;
return +(pi * r * r);
}
return { area: area };
}
// create and initialize the heap (64k)
var heap = new ArrayBuffer(0x10000);
init(heap, START, END);
// produce exports object,
// linked to AOT-compiled code
var circle = CircleModule(window, null, heap);
// calculate the area of a circle
circle.area(31);
@bmihaylov | Voxxed Days Thessaloniki 2016 19
Mozilla and Epic ported Unreal Engine 3 to the Web in 4 days
https://www.youtube.com/watch?v=XsyogXtyU9o
@bmihaylov | Voxxed Days Thessaloniki 2016 20
How compilers work
@bmihaylov | Voxxed Days Thessaloniki 2016 21
Source
program
Intermediate
Representation
Assembly or
machine
code
Frontend Backend
Static analysis
Semantic analysis
Code generation
Code optimization
asm.js compilation pipeline
@bmihaylov | Voxxed Days Thessaloniki 2016 22
C/C++
Fastcode
(LLVM backend)
Clang
JavaScript
engine
LLVM
bitcode
asm.js
Emscripten
Compiled JavaScript code can be
faster than handwritten JavaScript
@bmihaylov | Voxxed Days Thessaloniki 2016 23
Performance
@bmihaylov | Voxxed Days Thessaloniki 2016 24
0 2 4 6 8 10 12 14 16 18 20
bullet
zlib
skinning
Firefox Chrome Firefox+asm.js Native
source: http://kripken.github.io/mloc_emscripten_talk/#/28
аsm.js +++
@bmihaylov | Voxxed Days Thessaloniki 2016 25
Not a new language
Code is a subset of JavaScript
so it already runs in all browsers, if special support is missing
Code runs 2X slower than native
comparable to C# and Java
аsm.js ---
@bmihaylov | Voxxed Days Thessaloniki 2016 26
The parser becomes the bottleneck
once VMs optimize for it
We may want to do some different things
than what JavaScript allows us to do today
It is backed-up only by Mozilla
so far
WebAssembly = asm.js done right
@bmihaylov | Voxxed Days Thessaloniki 2016 27
Collaborative effort
@bmihaylov | Voxxed Days Thessaloniki 2016 28
+
many others…
WebAssembly
What is WebAssembly
@bmihaylov | Voxxed Days Thessaloniki 2016 29
A new language
short name is wasm
Improvement to JavaScript
and the browser
Compilation target from other languages
Modular structure
Integrates with ES6 modules
Abstract syntax tree
@bmihaylov | Voxxed Days Thessaloniki 2016 30
WebAssembly describes an AST
e.g., it supports branches and loops
It is possible to produce it directly
or compile it from another language
Binary & textual representation
Textual representation
@bmihaylov | Voxxed Days Thessaloniki 2016 31
Main purpose is human consumption
No official text representation yet
most examples use s-expressions
Used in browser developer tools
when no source maps exist
Example textual representation
@bmihaylov | Voxxed Days Thessaloniki 2016 32
asm.js module s-expressions format
function () {
"use asm";
function add(x, y) {
x = x | 0;
y = y | 0;
return x + y | 0;
}
return { add: add };
}
(module
(export $add “add” $add)
(func $add (param $x i32) (param $y i32) (result i32)
(i32.add
(get_local $x)
(get_local $y)
)
)
)
Binary representation
@bmihaylov | Voxxed Days Thessaloniki 2016 33
Reduction in payload size
about 20-30% smaller than the textual representation
Faster than parsing text
about 23x faster in the tests
Allows many optimization for the code
both size and decoding speed
The main format used by the browsers
How to use WebAssembly
@bmihaylov | Voxxed Days Thessaloniki 2016 34
1. Write code in any language
that can be compiled to WebAssembly
2. Compile the code
3. Load the output in the browser
Compiling to WebAssembly
@bmihaylov | Voxxed Days Thessaloniki 2016 35
Browser???C/C++
Fastcode
(LLVM backend)
Clang
LLVM
bitcode
asm.js
Emscripten
WebAssembly
Meet Binaryen
@bmihaylov | Voxxed Days Thessaloniki 2016 36
Compiler and toolchain infrastructure library for
WebAssembly
Parse & emit WebAssembly
Represent & process WebAssembly
Interpret WebAssembly
Binaryen
@bmihaylov | Voxxed Days Thessaloniki 2016 37
WebAssembly is a binary format and
we integrate it with Emscripten -> hence the name
Pronounced as bi-NAIR-ee-in
Rhymes with Targaryen
Game of Thrones
What comes with Binaryen
@bmihaylov | Voxxed Days Thessaloniki 2016 38
The Binary shell
It can load a WebAssembly module, transform it, execute it in an interpreter, etc.
asm2wasm / wasm2asm
Compiles asm.js to WebAssembly and vice versa
s2wasm
Compiles .s files, in the format of the new LLVM backend, to WebAssembly
wasm.js
A port of Binaryen itself to JavaScript
Compiling to WebAssembly
@bmihaylov | Voxxed Days Thessaloniki 2016 39
Browser
Binaryen
WebAssembly
C/C++
Fastcode
(LLVM backend)
Clang
LLVM
bitcode
asm.js
Emscripten
asm2wasm
New experimental LLVM backend
@bmihaylov | Voxxed Days Thessaloniki 2016 40
Browser
Binaryen
WebAssembly
C/C++
WebAssembly
LLVM backend
Clang
LLVM
bitcode
.s file
Emscripten
s2wasm
Compile from other languages
@bmihaylov | Voxxed Days Thessaloniki 2016 41
C/C++ Browser
WebAssembly
X Emscripten
Y
LLVM bitcode
WebAssembly is not bytecode
@bmihaylov | Voxxed Days Thessaloniki 2016 42
Bytecode is linear and stack-, register-, or SSA-based
WebAssembly is binary representation of an AST
WebAssembly is not versioned
It follows the same evolution cycle as JavaScript
WebAssembly will probably lead to universal VM
photo: frameitall.com
WebAssembly is sandboxed
@bmihaylov | Voxxed Days Thessaloniki 2016 43
WebAssembly vs. asm.js
@bmihaylov | Voxxed Days Thessaloniki 2016 44
Better load times
Binary format is much faster to parse than the textual representation of asm.js
Full threading support
SIMD
Single Instruction, Multiple Data
Integrated garbage collection
WebAssembly vs. asm.js
19
6.3
4.1
3
asm.js WebAssembly
Angry Bots demo size
MBs
MBs (compressed)
http://beta.unity3d.com/jonas/AngryBots/
@bmihaylov | Voxxed Days Thessaloniki 2016 45
WebAssembly today
@bmihaylov | Voxxed Days Thessaloniki 2016 46
What’s next
@bmihaylov | Voxxed Days Thessaloniki 2016 47
Define the official text representation
Further reduction in binary format size
Updates on the WebAssembly JavaScript API
Better documentation
for compiler writers, tool authors, hackers, and students
photo: panoramio.com
JavaScript will survive
at least for new
@bmihaylov | Voxxed Days Thessaloniki 2016 48
WebAssembly and JavaScript
@bmihaylov | Voxxed Days Thessaloniki 2016 49
WebAssembly JavaScript
Games,
video & image
decoders, etc.
External libraries
(e.g., C/C++)
@bmihaylov | Voxxed Days Thessaloniki 2016 50
WebAssembly fills in the gaps that would
be awkward to fill with JavaScript.
Eric Elliott
“
”
photo: www.adafruit.com
@bmihaylov | Voxxed Days Thessaloniki 2016 51
@bmihaylov | Voxxed Days Thessaloniki 2016 52
We think Swift should be everywhere and
used by everyone.
Craig Federighi
Apple’s WWDC 2015
“
”
@bmihaylov | Voxxed Days Thessaloniki 2016 53
54
Σας ευχαριστώ,
Θεσσαλονίκη
hey@boyan.in
@bmihaylov
After party
@bmihaylov | Voxxed Days Thessaloniki 2016

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

From C++ to JS via Emscripten
From C++ to JS via EmscriptenFrom C++ to JS via Emscripten
From C++ to JS via Emscripten
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
Introduction to stack's docker integration (1)
Introduction to stack's docker integration (1)Introduction to stack's docker integration (1)
Introduction to stack's docker integration (1)
 
ReactPHP: practical intro
ReactPHP:  practical introReactPHP:  practical intro
ReactPHP: practical intro
 
Super combinators
Super combinatorsSuper combinators
Super combinators
 
Kubernetes at Zalando - CNCF End User Committee Presentation
Kubernetes at Zalando - CNCF End User Committee PresentationKubernetes at Zalando - CNCF End User Committee Presentation
Kubernetes at Zalando - CNCF End User Committee Presentation
 
CF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACHCF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACH
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction Presentation
 
Multiplatform C++ on the Web with Emscripten
Multiplatform C++ on the Web with EmscriptenMultiplatform C++ on the Web with Emscripten
Multiplatform C++ on the Web with Emscripten
 
Making CLIs with Node.js
Making CLIs with Node.jsMaking CLIs with Node.js
Making CLIs with Node.js
 
Embedding Chromium into AGL demo platform with WAM
Embedding Chromium into AGL demo platform with WAMEmbedding Chromium into AGL demo platform with WAM
Embedding Chromium into AGL demo platform with WAM
 
The shift to the edge
The shift to the edgeThe shift to the edge
The shift to the edge
 
Web Assembly
Web AssemblyWeb Assembly
Web Assembly
 
Node.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScriptNode.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScript
 
From AWS/STUPS to Kubernetes on AWS @Zalando - Berlin Kubernetes Meetup
From AWS/STUPS to Kubernetes on AWS @Zalando - Berlin Kubernetes MeetupFrom AWS/STUPS to Kubernetes on AWS @Zalando - Berlin Kubernetes Meetup
From AWS/STUPS to Kubernetes on AWS @Zalando - Berlin Kubernetes Meetup
 
[Workshop] "Vuetify in practice", Alexander Stepanov
[Workshop] "Vuetify in practice", Alexander Stepanov[Workshop] "Vuetify in practice", Alexander Stepanov
[Workshop] "Vuetify in practice", Alexander Stepanov
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for RustJS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
 
Web assembly - Future of the Web
Web assembly - Future of the WebWeb assembly - Future of the Web
Web assembly - Future of the Web
 
Concourse ci container based ci for the cloud
Concourse ci   container based ci for the cloudConcourse ci   container based ci for the cloud
Concourse ci container based ci for the cloud
 
Whats new in .net core 3
Whats new in .net core 3Whats new in .net core 3
Whats new in .net core 3
 

Similar a Voxxed Days Thessaloniki 2016 - Web assembly : the browser vm we were waiting for

Web 2 . 0 .0 Programming Companies
Web 2 . 0 .0 Programming CompaniesWeb 2 . 0 .0 Programming Companies
Web 2 . 0 .0 Programming Companies
ebooker97
 
Web 2 . 0 .2 Coding Services
Web 2 . 0 .2 Coding ServicesWeb 2 . 0 .2 Coding Services
Web 2 . 0 .2 Coding Services
crackmaker00
 
Web 2 . .3 Development Services
Web 2 . .3 Development ServicesWeb 2 . .3 Development Services
Web 2 . .3 Development Services
Theawaster485
 
Web 2 . 0 .Zero Coding Services
Web 2 . 0 .Zero Coding ServicesWeb 2 . 0 .Zero Coding Services
Web 2 . 0 .Zero Coding Services
Theawaster485
 
Web 2 . .3 Development Services
Web 2 . .3 Development ServicesWeb 2 . .3 Development Services
Web 2 . .3 Development Services
Theawaster485
 

Similar a Voxxed Days Thessaloniki 2016 - Web assembly : the browser vm we were waiting for (20)

Boyan Mihaylov - Is web assembly the killer of javascript
Boyan Mihaylov - Is web assembly the killer of javascriptBoyan Mihaylov - Is web assembly the killer of javascript
Boyan Mihaylov - Is web assembly the killer of javascript
 
Web assembly brings the web to a new era
Web assembly brings the web to a new eraWeb assembly brings the web to a new era
Web assembly brings the web to a new era
 
How WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for AngularHow WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for Angular
 
Web 2 . 0 .0 Programming Companies
Web 2 . 0 .0 Programming CompaniesWeb 2 . 0 .0 Programming Companies
Web 2 . 0 .0 Programming Companies
 
Web 2 . 0 .2 Coding Services
Web 2 . 0 .2 Coding ServicesWeb 2 . 0 .2 Coding Services
Web 2 . 0 .2 Coding Services
 
Voxxed Athens 2018 - How WebAssembly is changing the Web and what it means to...
Voxxed Athens 2018 - How WebAssembly is changing the Web and what it means to...Voxxed Athens 2018 - How WebAssembly is changing the Web and what it means to...
Voxxed Athens 2018 - How WebAssembly is changing the Web and what it means to...
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016Angular2 & Native Script GDG DevFest 2016
Angular2 & Native Script GDG DevFest 2016
 
Web 2 . .3 Development Services
Web 2 . .3 Development ServicesWeb 2 . .3 Development Services
Web 2 . .3 Development Services
 
Web 2 . 0 .Zero Coding Services
Web 2 . 0 .Zero Coding ServicesWeb 2 . 0 .Zero Coding Services
Web 2 . 0 .Zero Coding Services
 
JS digest. Mid-Summer 2017
JS digest. Mid-Summer 2017JS digest. Mid-Summer 2017
JS digest. Mid-Summer 2017
 
We come in peace hybrid development with web assembly - Maayan Hanin
We come in peace hybrid development with web assembly - Maayan HaninWe come in peace hybrid development with web assembly - Maayan Hanin
We come in peace hybrid development with web assembly - Maayan Hanin
 
Web 2 . .3 Development Services
Web 2 . .3 Development ServicesWeb 2 . .3 Development Services
Web 2 . .3 Development Services
 
What's wrong with web
What's wrong with webWhat's wrong with web
What's wrong with web
 
Igalia and WebKit: Status update and plans
Igalia and WebKit: Status update and plansIgalia and WebKit: Status update and plans
Igalia and WebKit: Status update and plans
 
Web Application Frameworks - Web Technologies (1019888BNR)
Web Application Frameworks - Web Technologies (1019888BNR)Web Application Frameworks - Web Technologies (1019888BNR)
Web Application Frameworks - Web Technologies (1019888BNR)
 
WebAssembly and .NET
WebAssembly and .NETWebAssembly and .NET
WebAssembly and .NET
 
Javascript-lenguaje-conceptos-basicos.pdf
Javascript-lenguaje-conceptos-basicos.pdfJavascript-lenguaje-conceptos-basicos.pdf
Javascript-lenguaje-conceptos-basicos.pdf
 
Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assembly
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?
 

Más de Voxxed Days Thessaloniki

Más de Voxxed Days Thessaloniki (13)

Voxxed Days Thesaloniki 2016 - The Long Road
Voxxed Days Thesaloniki 2016 - The Long RoadVoxxed Days Thesaloniki 2016 - The Long Road
Voxxed Days Thesaloniki 2016 - The Long Road
 
Voxxed Days Thesaloniki 2016 - Scaling react.js applications
Voxxed Days Thesaloniki 2016 - Scaling react.js applicationsVoxxed Days Thesaloniki 2016 - Scaling react.js applications
Voxxed Days Thesaloniki 2016 - Scaling react.js applications
 
Voxxed Days Thesaloniki 2016 - Herding cats to a firefight
Voxxed Days Thesaloniki 2016 - Herding cats to a firefightVoxxed Days Thesaloniki 2016 - Herding cats to a firefight
Voxxed Days Thesaloniki 2016 - Herding cats to a firefight
 
Voxxed Days Thesaloniki 2016 - Streaming Engines for Big Data
Voxxed Days Thesaloniki 2016 - Streaming Engines for Big DataVoxxed Days Thesaloniki 2016 - Streaming Engines for Big Data
Voxxed Days Thesaloniki 2016 - Streaming Engines for Big Data
 
Voxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation AvoidanceVoxxed Days Thessaloniki 2016 - Documentation Avoidance
Voxxed Days Thessaloniki 2016 - Documentation Avoidance
 
Voxxed Days Thesaloniki 2016 - Rightsize Your Services with WildFly & WildFly...
Voxxed Days Thesaloniki 2016 - Rightsize Your Services with WildFly & WildFly...Voxxed Days Thesaloniki 2016 - Rightsize Your Services with WildFly & WildFly...
Voxxed Days Thesaloniki 2016 - Rightsize Your Services with WildFly & WildFly...
 
Voxxed Days Thessaloniki 2016 - Microservices in production
Voxxed Days Thessaloniki 2016 - Microservices in productionVoxxed Days Thessaloniki 2016 - Microservices in production
Voxxed Days Thessaloniki 2016 - Microservices in production
 
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 specVoxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
Voxxed Days Thesaloniki 2016 - Whirlwind tour through the HTTP2 spec
 
Voxxed Days Thesaloniki 2016 - Machine Learning for Developers
Voxxed Days Thesaloniki 2016 - Machine Learning for DevelopersVoxxed Days Thesaloniki 2016 - Machine Learning for Developers
Voxxed Days Thesaloniki 2016 - Machine Learning for Developers
 
Voxxed Days Thessaloniki 2016 - Continuous Delivery: Jenkins, Docker and Spri...
Voxxed Days Thessaloniki 2016 - Continuous Delivery: Jenkins, Docker and Spri...Voxxed Days Thessaloniki 2016 - Continuous Delivery: Jenkins, Docker and Spri...
Voxxed Days Thessaloniki 2016 - Continuous Delivery: Jenkins, Docker and Spri...
 
Voxxed Days Thesaloniki 2016 - 5 must have patterns for your web-scale micros...
Voxxed Days Thesaloniki 2016 - 5 must have patterns for your web-scale micros...Voxxed Days Thesaloniki 2016 - 5 must have patterns for your web-scale micros...
Voxxed Days Thesaloniki 2016 - 5 must have patterns for your web-scale micros...
 
Voxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on Azure
Voxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on AzureVoxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on Azure
Voxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on Azure
 
Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...
Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...
Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...
 

Último

Último (20)

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 

Voxxed Days Thessaloniki 2016 - Web assembly : the browser vm we were waiting for

  • 1. WebAssembly: the browser VM we were waiting for Boyan Mihaylov @bmihaylov
  • 2. Birth of JavaScript @bmihaylov | Voxxed Days Thessaloniki 2016 2 1995 Created by Brendan Eich in 10 days and released in Netscape Navigator 2.0
  • 3.
  • 4. Microsoft hits back @bmihaylov | Voxxed Days Thessaloniki 2016 4 19961995 Microsoft releases JScript in IE3
  • 5. Becoming a standard @bmihaylov | Voxxed Days Thessaloniki 2016 5 The first edition of ECMA-262 is released 199719961995
  • 7. @bmihaylov | Voxxed Days Thessaloniki 2016 7 The jQuery era
  • 8. JavaScript goes server-side @bmihaylov | Voxxed Days Thessaloniki 2016 8
  • 9. Mobile apps @bmihaylov | Voxxed Days Thessaloniki 2016 9
  • 10. JavaScript conquers the world @bmihaylov | Voxxed Days Thessaloniki 2016 10 source: https://www.codementor.io/learn-programming/beginner-programming-language-job-salary-community 102.3K 280.4K 431.7K 444.4K 512.1K 791.9K 953.9K 962.4K 1,699.7K 1,964.5K Swift Objective-C C# C C++ PHP Python Ruby Java JavaScript Total GitHub Projects (as of February 2016) 20.9K 31.6K 50.5K 67.7K 90.3K 112.0K 117.9K 125.1K 191.9K 200.1K Swift Ruby SQL C C++ Python C# PHP Java JavaScript StackOverflow Tag Followers (as of February 2016)
  • 11. @bmihaylov | Voxxed Days Thessaloniki 2016 11 The new Web
  • 12. We compile to JavaScript @bmihaylov | Voxxed Days Thessaloniki 2016 12
  • 13. New compilation source @bmihaylov | Voxxed Days Thessaloniki 2016 13
  • 14. Issues with JavaScript Just-In-Time compilation Types are inferred on runtime Variables can change types Automated garbage collection @bmihaylov | Voxxed Days Thessaloniki 2016 14
  • 15. Meet asm.js @bmihaylov | Voxxed Days Thessaloniki 2016 15 Started by Mozilla in 2013 It defines a subset of JavaScript Avoids potential slowdowns in code e.g., no variables with mixed type It does only low-level assembly-like computation exactly what compiled C/C++ needs
  • 16. @bmihaylov | Voxxed Days Thessaloniki 2016 16 C/C++ Emscripten .js .js + .html Node.js Web Browser
  • 17. Hello, world @bmihaylov | Voxxed Days Thessaloniki 2016 17 … function _main() { var $0 = 0, $vararg_buffer = 0, label = 0, sp = 0; sp = STACKTOP; STACKTOP = STACKTOP + 16|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abort(); $vararg_buffer = sp; $0 = 0; (_printf(672,$vararg_buffer)|0); STACKTOP = sp; return 0; } … #include<stdio.h> int main() { printf(“Hello, Thessaloniki“);; return 0; } C program (1KB) asm.js output (479KB)
  • 18. asm.js example @bmihaylov | Codemotion Milan 2015 18 asm.js module definition Usage in JavaScript function CircleModule(stdlib, foreign, heap) { "use asm"; var pi = +stdlib.Math.PI; function area(r) { r = r | 0; return +(pi * r * r); } return { area: area }; } // create and initialize the heap (64k) var heap = new ArrayBuffer(0x10000); init(heap, START, END); // produce exports object, // linked to AOT-compiled code var circle = CircleModule(window, null, heap); // calculate the area of a circle circle.area(31);
  • 19. @bmihaylov | Voxxed Days Thessaloniki 2016 19
  • 20. Mozilla and Epic ported Unreal Engine 3 to the Web in 4 days https://www.youtube.com/watch?v=XsyogXtyU9o @bmihaylov | Voxxed Days Thessaloniki 2016 20
  • 21. How compilers work @bmihaylov | Voxxed Days Thessaloniki 2016 21 Source program Intermediate Representation Assembly or machine code Frontend Backend Static analysis Semantic analysis Code generation Code optimization
  • 22. asm.js compilation pipeline @bmihaylov | Voxxed Days Thessaloniki 2016 22 C/C++ Fastcode (LLVM backend) Clang JavaScript engine LLVM bitcode asm.js Emscripten
  • 23. Compiled JavaScript code can be faster than handwritten JavaScript @bmihaylov | Voxxed Days Thessaloniki 2016 23
  • 24. Performance @bmihaylov | Voxxed Days Thessaloniki 2016 24 0 2 4 6 8 10 12 14 16 18 20 bullet zlib skinning Firefox Chrome Firefox+asm.js Native source: http://kripken.github.io/mloc_emscripten_talk/#/28
  • 25. аsm.js +++ @bmihaylov | Voxxed Days Thessaloniki 2016 25 Not a new language Code is a subset of JavaScript so it already runs in all browsers, if special support is missing Code runs 2X slower than native comparable to C# and Java
  • 26. аsm.js --- @bmihaylov | Voxxed Days Thessaloniki 2016 26 The parser becomes the bottleneck once VMs optimize for it We may want to do some different things than what JavaScript allows us to do today It is backed-up only by Mozilla so far
  • 27. WebAssembly = asm.js done right @bmihaylov | Voxxed Days Thessaloniki 2016 27
  • 28. Collaborative effort @bmihaylov | Voxxed Days Thessaloniki 2016 28 + many others… WebAssembly
  • 29. What is WebAssembly @bmihaylov | Voxxed Days Thessaloniki 2016 29 A new language short name is wasm Improvement to JavaScript and the browser Compilation target from other languages Modular structure Integrates with ES6 modules
  • 30. Abstract syntax tree @bmihaylov | Voxxed Days Thessaloniki 2016 30 WebAssembly describes an AST e.g., it supports branches and loops It is possible to produce it directly or compile it from another language Binary & textual representation
  • 31. Textual representation @bmihaylov | Voxxed Days Thessaloniki 2016 31 Main purpose is human consumption No official text representation yet most examples use s-expressions Used in browser developer tools when no source maps exist
  • 32. Example textual representation @bmihaylov | Voxxed Days Thessaloniki 2016 32 asm.js module s-expressions format function () { "use asm"; function add(x, y) { x = x | 0; y = y | 0; return x + y | 0; } return { add: add }; } (module (export $add “add” $add) (func $add (param $x i32) (param $y i32) (result i32) (i32.add (get_local $x) (get_local $y) ) ) )
  • 33. Binary representation @bmihaylov | Voxxed Days Thessaloniki 2016 33 Reduction in payload size about 20-30% smaller than the textual representation Faster than parsing text about 23x faster in the tests Allows many optimization for the code both size and decoding speed The main format used by the browsers
  • 34. How to use WebAssembly @bmihaylov | Voxxed Days Thessaloniki 2016 34 1. Write code in any language that can be compiled to WebAssembly 2. Compile the code 3. Load the output in the browser
  • 35. Compiling to WebAssembly @bmihaylov | Voxxed Days Thessaloniki 2016 35 Browser???C/C++ Fastcode (LLVM backend) Clang LLVM bitcode asm.js Emscripten WebAssembly
  • 36. Meet Binaryen @bmihaylov | Voxxed Days Thessaloniki 2016 36 Compiler and toolchain infrastructure library for WebAssembly Parse & emit WebAssembly Represent & process WebAssembly Interpret WebAssembly
  • 37. Binaryen @bmihaylov | Voxxed Days Thessaloniki 2016 37 WebAssembly is a binary format and we integrate it with Emscripten -> hence the name Pronounced as bi-NAIR-ee-in Rhymes with Targaryen Game of Thrones
  • 38. What comes with Binaryen @bmihaylov | Voxxed Days Thessaloniki 2016 38 The Binary shell It can load a WebAssembly module, transform it, execute it in an interpreter, etc. asm2wasm / wasm2asm Compiles asm.js to WebAssembly and vice versa s2wasm Compiles .s files, in the format of the new LLVM backend, to WebAssembly wasm.js A port of Binaryen itself to JavaScript
  • 39. Compiling to WebAssembly @bmihaylov | Voxxed Days Thessaloniki 2016 39 Browser Binaryen WebAssembly C/C++ Fastcode (LLVM backend) Clang LLVM bitcode asm.js Emscripten asm2wasm
  • 40. New experimental LLVM backend @bmihaylov | Voxxed Days Thessaloniki 2016 40 Browser Binaryen WebAssembly C/C++ WebAssembly LLVM backend Clang LLVM bitcode .s file Emscripten s2wasm
  • 41. Compile from other languages @bmihaylov | Voxxed Days Thessaloniki 2016 41 C/C++ Browser WebAssembly X Emscripten Y LLVM bitcode
  • 42. WebAssembly is not bytecode @bmihaylov | Voxxed Days Thessaloniki 2016 42 Bytecode is linear and stack-, register-, or SSA-based WebAssembly is binary representation of an AST WebAssembly is not versioned It follows the same evolution cycle as JavaScript WebAssembly will probably lead to universal VM
  • 43. photo: frameitall.com WebAssembly is sandboxed @bmihaylov | Voxxed Days Thessaloniki 2016 43
  • 44. WebAssembly vs. asm.js @bmihaylov | Voxxed Days Thessaloniki 2016 44 Better load times Binary format is much faster to parse than the textual representation of asm.js Full threading support SIMD Single Instruction, Multiple Data Integrated garbage collection
  • 45. WebAssembly vs. asm.js 19 6.3 4.1 3 asm.js WebAssembly Angry Bots demo size MBs MBs (compressed) http://beta.unity3d.com/jonas/AngryBots/ @bmihaylov | Voxxed Days Thessaloniki 2016 45
  • 46. WebAssembly today @bmihaylov | Voxxed Days Thessaloniki 2016 46
  • 47. What’s next @bmihaylov | Voxxed Days Thessaloniki 2016 47 Define the official text representation Further reduction in binary format size Updates on the WebAssembly JavaScript API Better documentation for compiler writers, tool authors, hackers, and students
  • 48. photo: panoramio.com JavaScript will survive at least for new @bmihaylov | Voxxed Days Thessaloniki 2016 48
  • 49. WebAssembly and JavaScript @bmihaylov | Voxxed Days Thessaloniki 2016 49 WebAssembly JavaScript Games, video & image decoders, etc. External libraries (e.g., C/C++)
  • 50. @bmihaylov | Voxxed Days Thessaloniki 2016 50 WebAssembly fills in the gaps that would be awkward to fill with JavaScript. Eric Elliott “ ” photo: www.adafruit.com
  • 51. @bmihaylov | Voxxed Days Thessaloniki 2016 51
  • 52. @bmihaylov | Voxxed Days Thessaloniki 2016 52 We think Swift should be everywhere and used by everyone. Craig Federighi Apple’s WWDC 2015 “ ”
  • 53. @bmihaylov | Voxxed Days Thessaloniki 2016 53