SlideShare a Scribd company logo
Web Performance
Q.pictures / pixelio.de
From Zero to Hero – Web Performance
Basti
• Sebastian Springer
• from Munich
• work @ MaibornWolff
• https://github.com/sspringer82
• @basti_springer
• JavaScript Developer
How to speed up
Margot Kessler / pixelio.de
your application
Do your own optimizations
Tim Reckmann / pixelio.de
Caching values
const arr = ['Peter', 'Paul', 'Mary'];

for (let i = 0; i < arr.length; i++) {

console.log(arr[i]);

} // 1.734ms





const arr = ['Peter', 'Paul', 'Mary'];

for (let i = 0, j = arr.length; i < j; i++) {

console.log(arr[i]);

} // 1.699ms
Optimisations of the engine
Dieter Schütz / pixelio.de
Remember your
optimisations?
const arr = ['Peter', 'Paul', 'Mary'];

for (let i = 0; i < arr.length; i++) {

console.log(arr[i]);

} // 1.734ms



for (let i = 0; i < arr.length; i++) {

console.log(arr[i]);

} // 0.079ms
2nd run
Optimisation
Optimising your JavaScript code is not your problem. Most
of the work is done by the engine itself. You just have to know
how your environment works.
Optimising your code is pointless, as it only reduces
readability.
Keep the big picture in mind!
What matters?
The time until your user sees the first
information and is able to interact with
your application.
Critical Rendering Path
Thorben Wengert / pixelio.de
Critical Rendering Path
Process between receiving HTML, CSS and JS files and
rendering the information in the users browser.
From Zero to Hero – Web Performance
From Zero to Hero – Web Performance
Critical Rendering Path
1. Processing HTML -> DOM

2. Processing CSS -> CSSOM

3. Building the Render Tree

4. Rendering
Processing HTML
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/constructing-the-object-model
https://creativecommons.org/licenses/by/3.0/
Processing CSS
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/constructing-the-object-model
https://creativecommons.org/licenses/by/3.0/
Building the Render Tree
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/constructing-the-object-model
https://creativecommons.org/licenses/by/3.0/
Measuring
Download
Karl-Heinz Laube / pixelio.de
Downloading files
A browser only has a limited number of parallel connections
to a server.
Firefox: 6
Chrome: 6
Internet Explorer: 13
Download
Deliver only a few small files
CSS: Preprocessors + Minifier
JS: Modulesystem + Minifier
Images: Sprites
Download
Service Worker
Service Worker
Separate browser process that act as a proxy between
browser and server. A service worker is able to intercept and
answer a request to a server directly.
Service workers are able to speed up applications and make
them available offline.
Service Worker
Blockades
lichtkunst.73 / pixelio.de
Render Blocking CSS
Receiving CSS files is blocking the render process of a
page.
The more CSS is used, the longer the blocking takes.
Render Blocking CSS
Do not use @import in your CSS - better pack everything in
just one file.
Use as little CSS as possible in the Critical Rendering Path.
The media attribute helps to reduce the processed CSS.
Last resort solution: inline CSS
Render Blocking JavaScript
All of the JavaScript that is not necessary for the initial page
load can be loaded at a later time.
Generating a script tag at the load event.
or lazy loading with a module loader such as webpack
App Shell Architecture
Minimal HTML, CSS and JavaScript as foundation for the
User Interface.
• loads fast
• can be cached
• shows dynamic content
Single Page
Applications
Tim Reckmann / pixelio.de
The user is moving within the application. The application
stays open in the browser over a long period of time.
Data is loaded over the whole lifecycle of the application.
There are no additional page loads
Application state is stored in memory.
Object representations are stored in memory.
Memory consumption increases over time.
JavaScript Engines
Rudolpho Duba / pixelio.de
JavaScript Engines
The competition between browser manufacturers brought up
some highly optimised engines.
JavaScript Engines
• Google Chrome: V8
• Mozilla Firefox: SpiderMonkey
• Microsoft Internet Explorer: Chakra
• Apple Safari: Nitro
Example: V8
V8 is a JavaScript engine specifically designed for fast
execution of large JavaScript applications.
Hidden Classes
Bernd Kasper / pixelio.de
Hidden Classes
For property access usually one big directory is used. To
speed up property access hidden classes per object is
used. The hidden class points to the location of a property in
memory.
function Point(x, y) {

this.x = x;

this.y = y;

}



var p1 = new Point(2, 4);
function Point(x, y) {

this.x = x;

this.y = y;

}



var p1 = new Point(2, 4);
p1
Hidden Class
C0
function Point(x, y) {

this.x = x;

this.y = y;

}



var p1 = new Point(2, 4);
p1
Hidden Class
C0
x: offset 0
Hidden Class
C0 Property x added -
use C1.
Hidden Class
C1
x: offset 0
function Point(x, y) {

this.x = x;

this.y = y;

}



var p1 = new Point(2, 4);
p1
Hidden Class
C2
x: offset 0
y: offset 1
Hidden Class
Property y added - use C2
Hidden Classes
Additional Object of the same type share the same hidden
classes and their transitions.
JIT Compiler
JIT Compiler
V8 compiles JavaScript code to machine code at first run.
The engine tries to guess the according hidden classes and
patches the machine code. All future usages of the object are
using the same hidden classes. If there’s a mismatch the
engine corrects it accordingly.
JIT Compiler
# ebx = the point object
cmp [ebx,<hidden class offset>],<cached hidden class>
jne <inline cache miss>
mov eax,[ebx, <cached x offset>]
p1.x
Garbage Collection
Moni Sertel / pixelio.de
Garbage Collection
V8 does memory management when the processor is idle to
reduce impact to the application.
The Garbage Collector regularly checks used memory and
frees unused memory.
Unused means: No more references to the object in memory.
Garbage Collection
new assigned memory
older objects
Memory structure
Most objects only have a short lifecycle
young generation
old generation
new assigned memory
Garbage Collection
Object1
Object2
Object3
Object1
Object2
Object3
older objects
Object1
As soon as one block is full, every used
object is moved to another block. The
old block is emptied afterwards.
If an object is moved for the second time
it’s moved to old generation space.
Garbage Collection
To speed up GC, you should try to move as few objects as
possible.
Garbage Collection
Where the young generation space is cleaned up with a
scavenge algorithm which is using a lot of memory, the old
generation space is cleaned up with a mark-and-sweep
collector.
Active objects are marked, all unmarked objects are
deleted.
A complete run takes 100 ms. Your application is stopped for
this time. V8 is able to do this process in increments which
take 5ms each.
JavaScript Engines
A lot optimisations of a browser engine only work for structures
which are used multiple times.
Repaints & Reflows
Tim Reckmann / pixelio.de
Repaints & Reflows
Repaint: Browser checks all elements for visibility, color,
measurements and other visual properties.
Repaints & Reflows
Reflow: The browser recalculates the layout of the page. A
reflow might cause reflows for other elements (children, or
siblings).
After a reflow a repaint is triggered.
Trigger for reflows
• Addition, removal or update of a DOM element
• Change of the content of a page
• Movement of an element
• Animations
• Reading measurements
• Change of CSS property
• Change of the class name of an element
• Addition or removal of a stylesheet
• Change of window size
• Scrolling
Omitting reflows
• Omit series of single style changes
• Collect operations in CSS classes
• Detach elements, change them, attach them to the
DOM
• Cache styles in JS variables
• Use fixed positions for animations
Profiling
Rendering: Recalculate Layout
Painting: Display the page
Memory Leaks
detlef menzel / pixelio.de
Memory Leaks
Memory leaks slow down an application, cause crashes and
increase latency.
A memory leak occurs, if memory is not used any more but
not freed by the GC.
Memory Leaks
Global variables
forgotten intervals
DOM elements in JS variables
Closures
Memory Leaks
var theThing = null;

var replaceThing = function () {

var originalThing = theThing;

var unused = function () {

if (originalThing)

console.log("hi");

};

theThing = {

longStr: new Array(1000000).join('*'),

someMethod: function () {

console.log(someMessage);

}

};

};

setInterval(replaceThing, 100);
http://info.meteor.com/blog/an-interesting-kind-of-javascript-memory-leak
Memory Leaks
Memory fills up
Animations
Tim Reckmann / pixelio.de
JavaScript Animations
If you’re doing animations with JavaScript, you periodically
change certain CSS properties of an object.
At 60 frames per second an animation is looking fluid.
function move(elem, to) {

var left = 0;

function frame() {

left++;

elem.style.left = left + 'px';

if (left === to) {

clearInterval(id)

}

}

var id = setInterval(frame, 10);

}



document.getElementById('outer').onclick = function () {

move(this.children[0], 500);

};
<div id="outer" class="outer">

<div id="inner" class="inner"></div>

</div>
HTML
CSS
Disadvantages
JavaScript is executed in the CPU and shares this resource
with a lot of other processes.
GC cycles can slow performance further down.
If your system is under load, animations are not fluid anymore.
Alternative
Web Animations API
https://developer.mozilla.org/en-US/docs/Web/API/
Web_Animations_API/Using_the_Web_Animations_API
Control your animations with JavaScript
Is not supported by all browsers yet.
CSS animations
CSS animations
CSS animations are calculated by the GPU and don’t create
load on the CPU.
CSS animations are more fluid than their JS counterpart.
Your browser is able to optimise your CSS animations.
document.getElementById('outer').onclick = function () {

this.children[0].className += ' move';

};
#inner {

transition: left 5s linear;

}

.move {

left: 500px;

}
<div id="outer" class="outer">

<div id="inner" class="inner"></div>

</div>
HTML
CSS
JS
CSS animations
If transitions are not enough, you can control animations with
@keyframes.
There are a lot of generators online (e.g. http://
cssanimate.com)
Prefetching
Prefetching
Your browser prefetches certain pages in order to load faster
if a user is browsing to that page. All browsers except Safari
support this attribute.
Chrome (49), IE (not Edge) and Opera are supporting
prerendering, where your browser prerenders the page to
further speed up display of a page.
<link rel="prefetch" href="users.html" />
How do others handle
performance?
Performance @facebook
A very good example of web performance tuning is the react
library. The virtual DOM provides an in memory structure on
which all the changes are performed. Afterwards all necessary
operations are calculated and performed in an optimised
operation to the actual DOM.
More performance
@facebook
To further improve performance, react introduces a full rewrite
of the reconciliation algorithm with version 16. In this version
there are different schedulers which determine when a
change should be performed.
Questions?
Rainer Sturm / pixelio.de
CONTACT
Sebastian Springer
sebastian.springer@maibornwolff.de
MaibornWolff GmbH
Theresienhöhe 13
80339 München
@basti_springer
https://github.com/sspringer82

More Related Content

PDF
Divide and Conquer – Microservices with Node.js
PDF
Creating Enterprise Web Applications with Node.js
PDF
Node Architecture and Getting Started with Express
PDF
React Development with the MERN Stack
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
PDF
Server Side Event Driven Programming
PPTX
Node.js: A Guided Tour
KEY
A million connections and beyond - Node.js at scale
Divide and Conquer – Microservices with Node.js
Creating Enterprise Web Applications with Node.js
Node Architecture and Getting Started with Express
React Development with the MERN Stack
Asynchronous I/O in NodeJS - new standard or challenges?
Server Side Event Driven Programming
Node.js: A Guided Tour
A million connections and beyond - Node.js at scale

What's hot (20)

PDF
All aboard the NodeJS Express
PDF
NodeJS for Beginner
PDF
KrakenJS
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PPT
RESTful API In Node Js using Express
PPTX
Kraken js at paypal
ODP
Introduce about Nodejs - duyetdev.com
PDF
Building servers with Node.js
PPTX
Intro to node and non blocking io
PPTX
Introduction to Node js
PPTX
Introduction Node.js
PPTX
Introduction to node.js
PDF
Play Framework: async I/O with Java and Scala
KEY
OSCON 2011 - Node.js Tutorial
PPTX
Java script at backend nodejs
KEY
Introduction to node.js
PPTX
Intro to Node.js (v1)
PPTX
Node.js Workshop - Sela SDP 2015
PDF
Real-Time Web Apps & Symfony. What are your options?
PDF
Celery with python
All aboard the NodeJS Express
NodeJS for Beginner
KrakenJS
Original slides from Ryan Dahl's NodeJs intro talk
RESTful API In Node Js using Express
Kraken js at paypal
Introduce about Nodejs - duyetdev.com
Building servers with Node.js
Intro to node and non blocking io
Introduction to Node js
Introduction Node.js
Introduction to node.js
Play Framework: async I/O with Java and Scala
OSCON 2011 - Node.js Tutorial
Java script at backend nodejs
Introduction to node.js
Intro to Node.js (v1)
Node.js Workshop - Sela SDP 2015
Real-Time Web Apps & Symfony. What are your options?
Celery with python
Ad

Similar to From Zero to Hero – Web Performance (20)

PPTX
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
PPTX
JavaScript front end performance optimizations
PDF
Front-end optimisation & jQuery Internals (Pycon)
PDF
Web Performance Part 4 "Client-side performance"
PDF
Practical tipsmakemobilefaster oscon2016
PDF
Fast mobile web apps
PDF
Your java script library
PDF
Of innovation and impatience - Future Decoded 2015
PDF
Performance (browser)
KEY
corporateJavascript
PPT
Ajax Performance
PDF
A call to JS Developers - Let’s stop trying to impress each other and start b...
PDF
Speeding up mobile web apps
KEY
Developing High Performance Web Apps - CodeMash 2011
PDF
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
PDF
Dev tools rendering & memory profiling
PDF
Are We Fast Yet? HTML & Javascript Performance - UtahJS
PPTX
Google V8 engine
PDF
Boston Web Performance Meetup: The Render Chain and You
PDF
New Features Coming in Browsers (RIT '09)
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
JavaScript front end performance optimizations
Front-end optimisation & jQuery Internals (Pycon)
Web Performance Part 4 "Client-side performance"
Practical tipsmakemobilefaster oscon2016
Fast mobile web apps
Your java script library
Of innovation and impatience - Future Decoded 2015
Performance (browser)
corporateJavascript
Ajax Performance
A call to JS Developers - Let’s stop trying to impress each other and start b...
Speeding up mobile web apps
Developing High Performance Web Apps - CodeMash 2011
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
Dev tools rendering & memory profiling
Are We Fast Yet? HTML & Javascript Performance - UtahJS
Google V8 engine
Boston Web Performance Meetup: The Render Chain and You
New Features Coming in Browsers (RIT '09)
Ad

More from Sebastian Springer (20)

PDF
HTMX - ist das die nächste Revolution im Web?
PDF
Schnelleinstieg in Angular
PDF
Von 0 auf 100 - Performance im Web
PDF
A/B Testing mit Node.js
PDF
PDF
Einführung in React
PDF
JavaScript Performance
PDF
ECMAScript 6 im Produktivbetrieb
PDF
Streams in Node.js
PDF
JavaScript Performance
PDF
Große Applikationen mit AngularJS
PDF
Testing tools
PDF
Node.js Security
PDF
Typescript
PDF
Reactive Programming
PDF
Best Practices für TDD in JavaScript
PDF
Warum ECMAScript 6 die Welt ein Stückchen besser macht
PDF
Lean Startup mit JavaScript
PDF
Webapplikationen mit Node.js
PDF
Node.js für Webapplikationen
HTMX - ist das die nächste Revolution im Web?
Schnelleinstieg in Angular
Von 0 auf 100 - Performance im Web
A/B Testing mit Node.js
Einführung in React
JavaScript Performance
ECMAScript 6 im Produktivbetrieb
Streams in Node.js
JavaScript Performance
Große Applikationen mit AngularJS
Testing tools
Node.js Security
Typescript
Reactive Programming
Best Practices für TDD in JavaScript
Warum ECMAScript 6 die Welt ein Stückchen besser macht
Lean Startup mit JavaScript
Webapplikationen mit Node.js
Node.js für Webapplikationen

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
top salesforce developer skills in 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administration Chapter 2
Navsoft: AI-Powered Business Solutions & Custom Software Development
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms I-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Which alternative to Crystal Reports is best for small or large businesses.pdf
Nekopoi APK 2025 free lastest update
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
top salesforce developer skills in 2025.pdf
L1 - Introduction to python Backend.pptx
Odoo Companies in India – Driving Business Transformation.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
ai tools demonstartion for schools and inter college
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administration Chapter 2

From Zero to Hero – Web Performance