SlideShare a Scribd company logo
Thibault Imbert
Group Product Manager | Web Platform
Workers of
the Web
Thibault Imbert
@thibault_imbert
Friday, August 23, 13
Records
Friday, August 23, 13
Brazilian disco-funk
Friday, August 23, 13
Brazilian disco-funk
Friday, August 23, 13
Brazilian disco-funk
Friday, August 23, 13
Brazilian disco-funk
Friday, August 23, 13
Brazil’s food
Friday, August 23, 13
Brazil’s food
Friday, August 23, 13
Brazil
Friday, August 23, 13
Estou me mudando para o Brasil
Friday, August 23, 13
Adobe & the web?
Friday, August 23, 13
Adobe & the web?
http://html.adobe.com/webplatform/
Friday, August 23, 13
Friday, August 23, 13
JavaScript concurrency
Friday, August 23, 13
JavaScript concurrency
Multithreading
Friday, August 23, 13
A single threaded world
Friday, August 23, 13
Examples
Friday, August 23, 13
Your budget
1000ms / 60fps = 16.67ms
Friday, August 23, 13
A frame
Rendering (repaint, reflow, etc.)
Network (XHR)
JavaScript (misc logic)6ms
2ms
8ms
16ms
UI Thread
Friday, August 23, 13
The budget
6ms
2ms
8ms
Budget
16ms
Rendering (repaint, reflow, etc.)
Network (XHR)
JavaScript (misc logic)
UI Thread
Friday, August 23, 13
12ms
4ms
10ms
Budget
Over budget
26ms
Rendering (repaint, reflow, etc.)
Network (XHR)
JavaScript (misc logic)
UI Thread
Friday, August 23, 13
Over budget
12ms
4ms
10ms
Budget
10ms
Rendering (repaint, reflow, etc.)
Network (XHR)
JavaScript (misc logic)
26ms
UI Thread
UI Impact
Friday, August 23, 13
6ms
4ms
20ms
Budget
Over budget
30ms
Rendering (repaint, reflow, etc.)
Network (XHR)
JavaScript (misc logic)
UI impact
UI Thread
Friday, August 23, 13
Dev tools
Time spent
Impact on fps
Friday, August 23, 13
So how do we fix that?
Friday, August 23, 13
Web Workers
Friday, August 23, 13
Support
Friday, August 23, 13
Detection
Friday, August 23, 13
Detection
function supports_web_workers() {
return window.Worker != null;
}
Friday, August 23, 13
Detection
function supports_web_workers() {
return window.Worker != null;
}
if (Modernizr.webworkers) {
// Workers are available
} else {
// fallback
}
Friday, August 23, 13
Most common use case
1. Responsive programming
When you have an expensive computation to perform
and don’t want to block the UI.
Friday, August 23, 13
By default, the UI thread
Rendering
Network
JavaScript6ms
2ms
8ms
16ms
UI Thread
Friday, August 23, 13
In parallel
Rendering
Network
JavaScript6ms
2ms
8ms
16ms
UI Thread
(Thread 1)
10ms
Web Worker
(Thread 2)
JavaScript
Friday, August 23, 13
In parallel
Rendering
Network
JavaScript6ms
2ms
8ms
16ms 28ms
JavaScript
UI Thread
(Thread 1)
Web Worker
(Thread 2)
Network
Friday, August 23, 13
In parallel
Rendering
Network
JavaScript6ms
2ms
8ms
16ms 44ms
JavaScript
UI Thread
(Thread 1)
Web Worker
(Thread 2)
Network
Friday, August 23, 13
In parallel
Rendering
Network
JavaScript6ms
2ms
8ms
16ms 44ms
UI Thread
(Thread 1)
Web Worker
(Thread 2)
Loading remote data
Parsing of XHR data
Encoding/Decoding
Physics
AI (pathfinding, etc.)
Friday, August 23, 13
Life as a worker
What is available:
XMLHttpRequest
The Application Cache
Spawning other web workers
The navigator object
The location object (read-only)
setTimeout()/clearTimeout() and setInterval()/clearInterval()
Importing external scripts using the importScripts() method
What is not:
The DOM
The window object
The document object
The parent object
Friday, August 23, 13
Web Workers == Threads ?
Workers and threads
Friday, August 23, 13
1. Workers are higher-level than threads and safe
First difference
Friday, August 23, 13
Why not threads?
Threads are hard to use.
Too low-level for web development.
We should not expose that level of complexity to web developers.
Locks, manual synchronization, race conditions, really?
Friday, August 23, 13
var worker = new Worker("background.js");
JSVM Impact on memory
Slow instantiation time
Thread
Higher-level than threads
Own heap
and stack
Friday, August 23, 13
2. Data passing
Second difference
Friday, August 23, 13
Threads and memory
Shared memory
Thread 2
Thread 5
Thread 1
Thread 4
Thread 3
Friday, August 23, 13
Threads and memory
Shared memory
Thread 2
Thread 5
Thread 1
Thread 4
Thread 3
Friday, August 23, 13
Threads and memory
Friday, August 23, 13
With Web Workers, nothing is shared
var worker1 = new Worker("background-task-1.js");
var worker3 = new Worker("background-task-3.js");
var worker2 = new Worker("background-task-2.js");
Cloning
Cloning
Transfer of
ownership
Friday, August 23, 13
1 Web Worker == 1 core ?
Workers and cores
Friday, August 23, 13
Workers and cores
UI Thread
(Thread 1)
Web Worker
(Thread 2)
Time
Single CPU
Friday, August 23, 13
Workers and cores
Time
Multicore
CPU
UI Thread
(Thread 1)
Web Worker
(Thread 2)
Friday, August 23, 13
Workers and cores
Friday, August 23, 13
Workers and cores
1. It is not possible to specify if a Web Worker
should run on a specific core.
Friday, August 23, 13
Workers and cores
1. It is not possible to specify if a Web Worker
should run on a specific core.
2. Web Workers on a single core CPU, will not run in
parallel but will still not block the UI.
Friday, August 23, 13
Workers and cores
1. It is not possible to specify if a Web Worker
should run on a specific core.
2. Web Workers on a single core CPU, will not run in
parallel but will still not block the UI.
3. On a multicore CPU, Web Workers can run truly in
parallel if the OS decides to.
Friday, August 23, 13
mostra o código!
Friday, August 23, 13
Creating a worker
// create a new worker
var worker = new Worker("background.js");
Friday, August 23, 13
Background logic
self.postMessage('Hello from Web Worker!');
// create a new worker
var worker = new Worker("background.js");
Current worker
Friday, August 23, 13
Background logic
self.postMessage('Hello from Web Worker!');
// create a new worker
var worker = new Worker("background.js");
Current worker Send data
Friday, August 23, 13
Background logic
self.postMessage('Hello from Web Worker!');
// create a new worker
var worker = new Worker("background.js");
// listen to the response from the Worker
worker.addEventListener('message', receiveMessage);
 
// callback handling the response, data is available in the event object
// outputs: Hello from Web Worker!
function receiveMessage (e)
{
    console.log (e.data);
}
Current worker Send data
Friday, August 23, 13
Catching errors
var width = document.innerWidth;
self.postMessage(width);
// create a new worker
var worker = new Worker("background.js");
// listen to the response from the Worker
worker.addEventListener('error', receiveMessage);
 
// callback handling the error
// outputs: Uncaught ReferenceError: document is not defined
function receiveMessage (e)
{
    console.log (e.data);
}
Trying to access an object not available from a Worker
Friday, August 23, 13
Data types supported for communication
Friday, August 23, 13
Data types supported for communication
Primitive types: Number, String, Boolean.
Friday, August 23, 13
Data types supported for communication
Primitive types: Number, String, Boolean.
Composite data types: plain JSON objects,
ImageData and TypedArray types.
Friday, August 23, 13
Running expensive computation
// create a new worker
var worker = new Worker("background.js");
// listen to the response from the Worker
worker.addEventListener('message', receiveMessage);
 
// callback handling the response, data is available in the event object
// outputs: 400000000
function receiveMessage (e)
{
    console.log (e.data);
}
var slowSquare = function (n) {
var i = 0;
while (++i < n * n) {}
return i;
};
self.postMessage ( slowSquare( 20000 ) );
Friday, August 23, 13
Examples
Friday, August 23, 13
Data cloning
self.postMessage('Hello from Web Worker!');
self.postMessage([1, 13, 34, 50]);
self.postMessage({name: Bob, age: 30});
self.postMessage([{name: Tom, age: 20}]);
Friday, August 23, 13
Data cloning
Web Worker A Web Worker B
clone
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
Web Worker A Web Worker B
clone
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
clone
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
[1, 13, 34, 50]
clone
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
[1, 13, 34, 50]
clone
data[2] = 100;
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
[1, 13, 34, 50]
clone
var incomingArray = e.data;
data[2] = 100;
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
[1, 13, 34, 50]
clone
var incomingArray = e.data;
// outputs: [1, 2, 3, 4]
console.log (incomingArray);
data[2] = 100;
Friday, August 23, 13
Data cloning
var data = [1, 2, 3, 4]
self.postMessage(data);
Web Worker A Web Worker B
[1, 13, 34, 50]
clone
var incomingArray = e.data;
// outputs: [1, 2, 3, 4]
console.log (incomingArray);
data[2] = 100;
Overhead
Friday, August 23, 13
Sending a 16mb typedarray with cloning
// Create a 16MB "file" and fill it.
var uInt8View = new Uint8Array(1024*1024*16);
for (var i = 0; i < uInt8View.length; ++i) {
    uInt8View[i] = i;
}
// transfer ownership to the worker
worker.postMessage(uInt8View.buffer);
Friday, August 23, 13
Platform Time (ms)
iOS7 (Safari/iPhone 5) 214
iOS6 (Safari/iPhone 4S) 524
MacBook Pro (Chrome/10.8.4) 75
Sending a 16mb typedarray
Friday, August 23, 13
Transfer of ownership
// Create a 16MB "file" and fill it.
var uInt8View = new Uint8Array(1024*1024*16);
for (var i = 0; i < uInt8View.length; ++i) {
    uInt8View[i] = i;
}
// transfer ownership to the worker
worker.postMessage(uInt8View.buffer, [uInt8View.buffer]);
Friday, August 23, 13
Transfer of ownership
Web Worker A Web Worker B
reference transferred
to Web Worker B
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
Web Worker A Web Worker B
reference transferred
to Web Worker B
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
self.postMessage(uInt8View.buffer,
Web Worker A Web Worker B
reference transferred
to Web Worker B
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
self.postMessage(uInt8View.buffer,
[uInt8View.buffer]);
Web Worker A Web Worker B
reference transferred
to Web Worker B
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
self.postMessage(uInt8View.buffer,
[uInt8View.buffer]);
Web Worker A Web Worker B
reference transferred
to Web Worker B
// triggers runtime exception
uInt8View.buffer = 12;
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
self.postMessage(uInt8View.buffer,
[uInt8View.buffer]);
Web Worker A Web Worker B
reference transferred
to Web Worker B
var incomingArray = e.data;
// triggers runtime exception
uInt8View.buffer = 12;
Friday, August 23, 13
Transfer of ownership
var data = [1, 2, 3, 4]
self.postMessage(uInt8View.buffer,
[uInt8View.buffer]);
Web Worker A Web Worker B
reference transferred
to Web Worker B
var incomingArray = e.data;
// outputs: [1, 2, 3, 4]
console.log (incomingArray);
// triggers runtime exception
uInt8View.buffer = 12;
Friday, August 23, 13
Transfer of ownership, almost a 3x boost
Platform Time (ms)
iOS7 (Safari/iPhone 5) 80 (was 214)
iOS6 (Safari/iPhone 4S) 162 (was 524)
MacBook Pro (Chrome/10.8.4) 37 (was 75)
Friday, August 23, 13
Exciting use case
Friday, August 23, 13
Exciting use case
2. Parallel programming
Friday, August 23, 13
Exciting use case
2. Parallel programming
When you want to leverage multiple CPU cores by
having computations running concurrently to solve a
specific task.
Friday, August 23, 13
Parallelization
Friday, August 23, 13
Parallelization
Friday, August 23, 13
Parallelization
Worker 1 Worker 2
Worker 4Worker 3
Friday, August 23, 13
But...
Friday, August 23, 13
But...
1. Cloning overhead is high and limits
parallelization opportunities.
Friday, August 23, 13
But...
1. Cloning overhead is high and limits
parallelization opportunities.
2. Transfer of ownership does not work for
parallelization.
Friday, August 23, 13
But...
1. Cloning overhead is high and limits
parallelization opportunities.
2. Transfer of ownership does not work for
parallelization.
3. A more efficient communication model has to
be designed for Web Workers to allow faster
communication.
Friday, August 23, 13
But...
1. Cloning overhead is high and limits
parallelization opportunities.
2. Transfer of ownership does not work for
parallelization.
3. A more efficient communication model has to
be designed for Web Workers to allow faster
communication.
Software transactional memory?
Friday, August 23, 13
Friday, August 23, 13
OK, let’s see if you remember the main points.
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
To summarize
1. Leverage Web Workers if you don’t want your UI
to lock: true or false?
2. Web Workers are available pretty much
everywhere on desktop and mobile: true or false?
3. Web Workers are as low-level as threads: true
or false?
4. Message cloning is faster than transfer of
ownership: true or false?
5. Web Workers work great to keep the UI
responsive: true or false?
6. Parallel programming and responsive
programming are the same things: true or false?
Friday, August 23, 13
@thibault_imbert
Blog: typedarray.org
obrigado!
Slides: http://bit.ly/13Lbk8d/
More details: http://bit.ly/14IWKKj
Friday, August 23, 13

More Related Content

Similar to Workers of the web - BrazilJS 2013

Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
Sira Sujjinanont
 
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of ThingsHTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
Jesse Cravens
 
Introduction to Twitter Storm
Introduction to Twitter StormIntroduction to Twitter Storm
Introduction to Twitter Storm
Uwe Printz
 
Continuous Delivery at Netflix
Continuous Delivery at NetflixContinuous Delivery at Netflix
Continuous Delivery at Netflix
Rob Spieldenner
 
2013 jsdc webworker
2013 jsdc webworker2013 jsdc webworker
2013 jsdc webworker
Bingo Yang
 
Securing Client Side Data
 Securing Client Side Data Securing Client Side Data
Securing Client Side Data
Grgur Grisogono
 
JavaScript Makers: How JS is Helping Drive the Maker Movement
JavaScript Makers: How JS is Helping Drive the Maker MovementJavaScript Makers: How JS is Helping Drive the Maker Movement
JavaScript Makers: How JS is Helping Drive the Maker Movement
Jesse Cravens
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
codeofficer
 
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
swentel
 
실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3NAVER D2
 
Continuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformContinuous Delivery for the Web Platform
Continuous Delivery for the Web Platform
Jarrod Overson
 
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsDark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsKoan-Sin Tan
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
Ben Hall
 
UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)
Mark Proctor
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
Oursky
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
Jane Chung
 
Sling tracer and Chrome Plugin to the Rescue
Sling tracer and Chrome Plugin to the RescueSling tracer and Chrome Plugin to the Rescue
Sling tracer and Chrome Plugin to the Rescue
Chetan Mehrotra
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
Ted Husted
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applications
ashleypuls
 

Similar to Workers of the web - BrazilJS 2013 (20)

Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of ThingsHTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
HTML5.tx 2013: Embedded JavaScript, HTML5 and the Internet of Things
 
Introduction to Twitter Storm
Introduction to Twitter StormIntroduction to Twitter Storm
Introduction to Twitter Storm
 
Continuous Delivery at Netflix
Continuous Delivery at NetflixContinuous Delivery at Netflix
Continuous Delivery at Netflix
 
2013 jsdc webworker
2013 jsdc webworker2013 jsdc webworker
2013 jsdc webworker
 
Securing Client Side Data
 Securing Client Side Data Securing Client Side Data
Securing Client Side Data
 
JavaScript Makers: How JS is Helping Drive the Maker Movement
JavaScript Makers: How JS is Helping Drive the Maker MovementJavaScript Makers: How JS is Helping Drive the Maker Movement
JavaScript Makers: How JS is Helping Drive the Maker Movement
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
 
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
Drupal 8 configuration system for coders and site builders - DrupalCamp Balti...
 
실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3
 
Continuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformContinuous Delivery for the Web Platform
Continuous Delivery for the Web Platform
 
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsDark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
 
UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
 
Sling tracer and Chrome Plugin to the Rescue
Sling tracer and Chrome Plugin to the RescueSling tracer and Chrome Plugin to the Rescue
Sling tracer and Chrome Plugin to the Rescue
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applications
 

More from Thibault Imbert

How to Hire the Right Growth Team
How to Hire the Right Growth TeamHow to Hire the Right Growth Team
How to Hire the Right Growth Team
Thibault Imbert
 
Why and how you should build a growth team?
Why and how you should build a growth team?Why and how you should build a growth team?
Why and how you should build a growth team?
Thibault Imbert
 
How to build a framework for customer empathy
How to build a framework for customer empathyHow to build a framework for customer empathy
How to build a framework for customer empathy
Thibault Imbert
 
Growth Hacking Conference '17 - Antwerp
Growth Hacking Conference '17 - AntwerpGrowth Hacking Conference '17 - Antwerp
Growth Hacking Conference '17 - Antwerp
Thibault Imbert
 
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth CultureGrowth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
Thibault Imbert
 
Growth in unexpected places
Growth in unexpected placesGrowth in unexpected places
Growth in unexpected places
Thibault Imbert
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
Thibault Imbert
 

More from Thibault Imbert (7)

How to Hire the Right Growth Team
How to Hire the Right Growth TeamHow to Hire the Right Growth Team
How to Hire the Right Growth Team
 
Why and how you should build a growth team?
Why and how you should build a growth team?Why and how you should build a growth team?
Why and how you should build a growth team?
 
How to build a framework for customer empathy
How to build a framework for customer empathyHow to build a framework for customer empathy
How to build a framework for customer empathy
 
Growth Hacking Conference '17 - Antwerp
Growth Hacking Conference '17 - AntwerpGrowth Hacking Conference '17 - Antwerp
Growth Hacking Conference '17 - Antwerp
 
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth CultureGrowth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
Growth Marketing Conference '17 Atlanta - Creating a Company Wide Growth Culture
 
Growth in unexpected places
Growth in unexpected placesGrowth in unexpected places
Growth in unexpected places
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Workers of the web - BrazilJS 2013

  • 1. Thibault Imbert Group Product Manager | Web Platform Workers of the Web Thibault Imbert @thibault_imbert Friday, August 23, 13
  • 10. Estou me mudando para o Brasil Friday, August 23, 13
  • 11. Adobe & the web? Friday, August 23, 13
  • 12. Adobe & the web? http://html.adobe.com/webplatform/ Friday, August 23, 13
  • 16. A single threaded world Friday, August 23, 13
  • 18. Your budget 1000ms / 60fps = 16.67ms Friday, August 23, 13
  • 19. A frame Rendering (repaint, reflow, etc.) Network (XHR) JavaScript (misc logic)6ms 2ms 8ms 16ms UI Thread Friday, August 23, 13
  • 20. The budget 6ms 2ms 8ms Budget 16ms Rendering (repaint, reflow, etc.) Network (XHR) JavaScript (misc logic) UI Thread Friday, August 23, 13
  • 21. 12ms 4ms 10ms Budget Over budget 26ms Rendering (repaint, reflow, etc.) Network (XHR) JavaScript (misc logic) UI Thread Friday, August 23, 13
  • 22. Over budget 12ms 4ms 10ms Budget 10ms Rendering (repaint, reflow, etc.) Network (XHR) JavaScript (misc logic) 26ms UI Thread UI Impact Friday, August 23, 13
  • 23. 6ms 4ms 20ms Budget Over budget 30ms Rendering (repaint, reflow, etc.) Network (XHR) JavaScript (misc logic) UI impact UI Thread Friday, August 23, 13
  • 24. Dev tools Time spent Impact on fps Friday, August 23, 13
  • 25. So how do we fix that? Friday, August 23, 13
  • 29. Detection function supports_web_workers() { return window.Worker != null; } Friday, August 23, 13
  • 30. Detection function supports_web_workers() { return window.Worker != null; } if (Modernizr.webworkers) { // Workers are available } else { // fallback } Friday, August 23, 13
  • 31. Most common use case 1. Responsive programming When you have an expensive computation to perform and don’t want to block the UI. Friday, August 23, 13
  • 32. By default, the UI thread Rendering Network JavaScript6ms 2ms 8ms 16ms UI Thread Friday, August 23, 13
  • 33. In parallel Rendering Network JavaScript6ms 2ms 8ms 16ms UI Thread (Thread 1) 10ms Web Worker (Thread 2) JavaScript Friday, August 23, 13
  • 34. In parallel Rendering Network JavaScript6ms 2ms 8ms 16ms 28ms JavaScript UI Thread (Thread 1) Web Worker (Thread 2) Network Friday, August 23, 13
  • 35. In parallel Rendering Network JavaScript6ms 2ms 8ms 16ms 44ms JavaScript UI Thread (Thread 1) Web Worker (Thread 2) Network Friday, August 23, 13
  • 36. In parallel Rendering Network JavaScript6ms 2ms 8ms 16ms 44ms UI Thread (Thread 1) Web Worker (Thread 2) Loading remote data Parsing of XHR data Encoding/Decoding Physics AI (pathfinding, etc.) Friday, August 23, 13
  • 37. Life as a worker What is available: XMLHttpRequest The Application Cache Spawning other web workers The navigator object The location object (read-only) setTimeout()/clearTimeout() and setInterval()/clearInterval() Importing external scripts using the importScripts() method What is not: The DOM The window object The document object The parent object Friday, August 23, 13
  • 38. Web Workers == Threads ? Workers and threads Friday, August 23, 13
  • 39. 1. Workers are higher-level than threads and safe First difference Friday, August 23, 13
  • 40. Why not threads? Threads are hard to use. Too low-level for web development. We should not expose that level of complexity to web developers. Locks, manual synchronization, race conditions, really? Friday, August 23, 13
  • 41. var worker = new Worker("background.js"); JSVM Impact on memory Slow instantiation time Thread Higher-level than threads Own heap and stack Friday, August 23, 13
  • 42. 2. Data passing Second difference Friday, August 23, 13
  • 43. Threads and memory Shared memory Thread 2 Thread 5 Thread 1 Thread 4 Thread 3 Friday, August 23, 13
  • 44. Threads and memory Shared memory Thread 2 Thread 5 Thread 1 Thread 4 Thread 3 Friday, August 23, 13
  • 45. Threads and memory Friday, August 23, 13
  • 46. With Web Workers, nothing is shared var worker1 = new Worker("background-task-1.js"); var worker3 = new Worker("background-task-3.js"); var worker2 = new Worker("background-task-2.js"); Cloning Cloning Transfer of ownership Friday, August 23, 13
  • 47. 1 Web Worker == 1 core ? Workers and cores Friday, August 23, 13
  • 48. Workers and cores UI Thread (Thread 1) Web Worker (Thread 2) Time Single CPU Friday, August 23, 13
  • 49. Workers and cores Time Multicore CPU UI Thread (Thread 1) Web Worker (Thread 2) Friday, August 23, 13
  • 50. Workers and cores Friday, August 23, 13
  • 51. Workers and cores 1. It is not possible to specify if a Web Worker should run on a specific core. Friday, August 23, 13
  • 52. Workers and cores 1. It is not possible to specify if a Web Worker should run on a specific core. 2. Web Workers on a single core CPU, will not run in parallel but will still not block the UI. Friday, August 23, 13
  • 53. Workers and cores 1. It is not possible to specify if a Web Worker should run on a specific core. 2. Web Workers on a single core CPU, will not run in parallel but will still not block the UI. 3. On a multicore CPU, Web Workers can run truly in parallel if the OS decides to. Friday, August 23, 13
  • 54. mostra o código! Friday, August 23, 13
  • 55. Creating a worker // create a new worker var worker = new Worker("background.js"); Friday, August 23, 13
  • 56. Background logic self.postMessage('Hello from Web Worker!'); // create a new worker var worker = new Worker("background.js"); Current worker Friday, August 23, 13
  • 57. Background logic self.postMessage('Hello from Web Worker!'); // create a new worker var worker = new Worker("background.js"); Current worker Send data Friday, August 23, 13
  • 58. Background logic self.postMessage('Hello from Web Worker!'); // create a new worker var worker = new Worker("background.js"); // listen to the response from the Worker worker.addEventListener('message', receiveMessage);   // callback handling the response, data is available in the event object // outputs: Hello from Web Worker! function receiveMessage (e) {     console.log (e.data); } Current worker Send data Friday, August 23, 13
  • 59. Catching errors var width = document.innerWidth; self.postMessage(width); // create a new worker var worker = new Worker("background.js"); // listen to the response from the Worker worker.addEventListener('error', receiveMessage);   // callback handling the error // outputs: Uncaught ReferenceError: document is not defined function receiveMessage (e) {     console.log (e.data); } Trying to access an object not available from a Worker Friday, August 23, 13
  • 60. Data types supported for communication Friday, August 23, 13
  • 61. Data types supported for communication Primitive types: Number, String, Boolean. Friday, August 23, 13
  • 62. Data types supported for communication Primitive types: Number, String, Boolean. Composite data types: plain JSON objects, ImageData and TypedArray types. Friday, August 23, 13
  • 63. Running expensive computation // create a new worker var worker = new Worker("background.js"); // listen to the response from the Worker worker.addEventListener('message', receiveMessage);   // callback handling the response, data is available in the event object // outputs: 400000000 function receiveMessage (e) {     console.log (e.data); } var slowSquare = function (n) { var i = 0; while (++i < n * n) {} return i; }; self.postMessage ( slowSquare( 20000 ) ); Friday, August 23, 13
  • 65. Data cloning self.postMessage('Hello from Web Worker!'); self.postMessage([1, 13, 34, 50]); self.postMessage({name: Bob, age: 30}); self.postMessage([{name: Tom, age: 20}]); Friday, August 23, 13
  • 66. Data cloning Web Worker A Web Worker B clone Friday, August 23, 13
  • 67. Data cloning var data = [1, 2, 3, 4] Web Worker A Web Worker B clone Friday, August 23, 13
  • 68. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B clone Friday, August 23, 13
  • 69. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B [1, 13, 34, 50] clone Friday, August 23, 13
  • 70. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B [1, 13, 34, 50] clone data[2] = 100; Friday, August 23, 13
  • 71. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B [1, 13, 34, 50] clone var incomingArray = e.data; data[2] = 100; Friday, August 23, 13
  • 72. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B [1, 13, 34, 50] clone var incomingArray = e.data; // outputs: [1, 2, 3, 4] console.log (incomingArray); data[2] = 100; Friday, August 23, 13
  • 73. Data cloning var data = [1, 2, 3, 4] self.postMessage(data); Web Worker A Web Worker B [1, 13, 34, 50] clone var incomingArray = e.data; // outputs: [1, 2, 3, 4] console.log (incomingArray); data[2] = 100; Overhead Friday, August 23, 13
  • 74. Sending a 16mb typedarray with cloning // Create a 16MB "file" and fill it. var uInt8View = new Uint8Array(1024*1024*16); for (var i = 0; i < uInt8View.length; ++i) {     uInt8View[i] = i; } // transfer ownership to the worker worker.postMessage(uInt8View.buffer); Friday, August 23, 13
  • 75. Platform Time (ms) iOS7 (Safari/iPhone 5) 214 iOS6 (Safari/iPhone 4S) 524 MacBook Pro (Chrome/10.8.4) 75 Sending a 16mb typedarray Friday, August 23, 13
  • 76. Transfer of ownership // Create a 16MB "file" and fill it. var uInt8View = new Uint8Array(1024*1024*16); for (var i = 0; i < uInt8View.length; ++i) {     uInt8View[i] = i; } // transfer ownership to the worker worker.postMessage(uInt8View.buffer, [uInt8View.buffer]); Friday, August 23, 13
  • 77. Transfer of ownership Web Worker A Web Worker B reference transferred to Web Worker B Friday, August 23, 13
  • 78. Transfer of ownership var data = [1, 2, 3, 4] Web Worker A Web Worker B reference transferred to Web Worker B Friday, August 23, 13
  • 79. Transfer of ownership var data = [1, 2, 3, 4] self.postMessage(uInt8View.buffer, Web Worker A Web Worker B reference transferred to Web Worker B Friday, August 23, 13
  • 80. Transfer of ownership var data = [1, 2, 3, 4] self.postMessage(uInt8View.buffer, [uInt8View.buffer]); Web Worker A Web Worker B reference transferred to Web Worker B Friday, August 23, 13
  • 81. Transfer of ownership var data = [1, 2, 3, 4] self.postMessage(uInt8View.buffer, [uInt8View.buffer]); Web Worker A Web Worker B reference transferred to Web Worker B // triggers runtime exception uInt8View.buffer = 12; Friday, August 23, 13
  • 82. Transfer of ownership var data = [1, 2, 3, 4] self.postMessage(uInt8View.buffer, [uInt8View.buffer]); Web Worker A Web Worker B reference transferred to Web Worker B var incomingArray = e.data; // triggers runtime exception uInt8View.buffer = 12; Friday, August 23, 13
  • 83. Transfer of ownership var data = [1, 2, 3, 4] self.postMessage(uInt8View.buffer, [uInt8View.buffer]); Web Worker A Web Worker B reference transferred to Web Worker B var incomingArray = e.data; // outputs: [1, 2, 3, 4] console.log (incomingArray); // triggers runtime exception uInt8View.buffer = 12; Friday, August 23, 13
  • 84. Transfer of ownership, almost a 3x boost Platform Time (ms) iOS7 (Safari/iPhone 5) 80 (was 214) iOS6 (Safari/iPhone 4S) 162 (was 524) MacBook Pro (Chrome/10.8.4) 37 (was 75) Friday, August 23, 13
  • 85. Exciting use case Friday, August 23, 13
  • 86. Exciting use case 2. Parallel programming Friday, August 23, 13
  • 87. Exciting use case 2. Parallel programming When you want to leverage multiple CPU cores by having computations running concurrently to solve a specific task. Friday, August 23, 13
  • 90. Parallelization Worker 1 Worker 2 Worker 4Worker 3 Friday, August 23, 13
  • 92. But... 1. Cloning overhead is high and limits parallelization opportunities. Friday, August 23, 13
  • 93. But... 1. Cloning overhead is high and limits parallelization opportunities. 2. Transfer of ownership does not work for parallelization. Friday, August 23, 13
  • 94. But... 1. Cloning overhead is high and limits parallelization opportunities. 2. Transfer of ownership does not work for parallelization. 3. A more efficient communication model has to be designed for Web Workers to allow faster communication. Friday, August 23, 13
  • 95. But... 1. Cloning overhead is high and limits parallelization opportunities. 2. Transfer of ownership does not work for parallelization. 3. A more efficient communication model has to be designed for Web Workers to allow faster communication. Software transactional memory? Friday, August 23, 13
  • 97. OK, let’s see if you remember the main points. Friday, August 23, 13
  • 98. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 99. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 100. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 101. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 102. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 103. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 104. To summarize 1. Leverage Web Workers if you don’t want your UI to lock: true or false? 2. Web Workers are available pretty much everywhere on desktop and mobile: true or false? 3. Web Workers are as low-level as threads: true or false? 4. Message cloning is faster than transfer of ownership: true or false? 5. Web Workers work great to keep the UI responsive: true or false? 6. Parallel programming and responsive programming are the same things: true or false? Friday, August 23, 13
  • 105. @thibault_imbert Blog: typedarray.org obrigado! Slides: http://bit.ly/13Lbk8d/ More details: http://bit.ly/14IWKKj Friday, August 23, 13