SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Rendering Optimizations
A few insights on how to cope with high quality, rich webapps
Apr. 2013

Arthur Jamain
arthur@joshfire.com
CONTEXT
What’s going on and where ?
CONTEXT

TECHNOLOGIES

• Rich HTML5/JS Applications
expected to behave like a
native app.


• Basic access to native
features


• Low resources, high-end
display
Joshfire
CONTEXT

OBJECTIVES

• High expectations of UX quality

• Heavy content : lengthy videos
or images lists, overall rich UIs


• Animations and multidirectional
nested scrolling


• Cost effectiveness.
Joshfire
CONTEXT

VALIDITY

• Most of the concepts described in this presentation
are heavily platform dependent


• Rendering engines do implement the same
specifications but in different forms, and future
evolutions may invalidate this document.


• The current (early 2013) implementations of iOS,
Android, BB10, Microsoft... devices' default web
engines all fit this document
Joshfire
WEBAPPS
General Considerations
WEBAPPS

RUNTIME

• A Native Webview runs the HTML5 App
• Alongside are plugins : camera, sensors, etc.
• The Webview is entirely opaque to the native

runtime
o No (native) memory handling / garbage collection
o

No pre-rendering / dynamic loading / caching of
table cells, list views or scroll views

o

Sparse critical error handling

Joshfire
WEBAPPS

RENDERING

• The one Webview's engine renders the whole
app

o We're talking UI here, it is fairly easy to defer
big calculations to native components.

• Its size in memory and its resource consumption
are "unitary"

• It can use the device's processor, RAM and
GPU to achieve its rendering process

• Decreasing the Webview’s (hence, the app)
resource consumption can only be done by
altering the JS / CSS / HTML code which
determines what is rendered and how.
Joshfire
PAGE RENDERING
In the kingdom of the blind …
RENDERING

WHAT IS IT ?

• The process of

JS

HTML
load, parse

transforming the document
into what we see on our

CSS

Alter

DOM Tree

screen.

• Input : DOM (nodes, CSS)
• Output : Bitmaps to be

Render Tree
& Render Layer Tree

drawn on the browsers'
Rendered Bitmap

canvas
Joshfire
RENDERING

THE RENDER TREE

• Ordered tree of visual elements (“renderers”) representing the
DOM elements


• Enables painting the contents in their correct order

• DOM Nodes spawn one or more renderers under certain
conditions only : display mode, visibility...


• Their ordering depends on their box-model settings, sizing rules,
etc.


• Controlling the size and depth of the render tree allows control of
the rendering performances

Joshfire
RENDERING

THE RENDER TREE

Check these options in
Chrome&Co. to visualize
the content rectangles

• Each renderer has children renderers
• Each renderer draws a rectangle defined by its computed CSS
properties and its children’s ones.

Joshfire
RENDERING

LAYERS !

• The browser then draws a
•
•
•

grid of rectangles.
Controlled-size layers —
hence keeping several
smaller objects in memory
The renderer's rectangles
are split among these
"master" layers/rectangles
These rectangles are then
printed as bitmaps on the
screen, asynchronously.

Note : These layers or tiles are drawn by the GPU

Joshfire

Html content that spans on
the whole page.

Note that the grey element
is split and drawn among 4
tiles
Stop !
Recap time.
RECAP

DOM Tree

• Initially, and whenever the drawing loop ticks :!
o The DOM nodes that have changed spawn

Render Tree

and modify renderers accordingly, creating or
completing the rendering tree!
o Renderers calculate their respective

Render Layer Tree (Grid
and layers)

rectangles and their contents!
o These rectangles are projected onto cells of
GPU

a grid!
o Each cell of the grid is drawn as a bitmap on
the screen by the GPU
Joshfire
RENDERING

OPTIMIZATIONS
HACK AROUND
OPTIM

HARDWARE ACCELERATION

• Tiling may produce weird

•
•

visual effects

o They are drawn on a single
thread, asynchronously.

o Heavier tiles may be
drawn visually significantly
after lighter tiles

To avoid this, we grant large
elements their own "master"
layers !

This is what "accelerating" an
element refers to.

Joshfire

The “accelerated” node is
drawn as one solid
rectangle and is not split
OPTIM

USING ACCELERATION

• Some renderers in the render
•

•

tree can be sent "on top"
This happens when an element
undergoes one of several
transformations — such as a
rotation or the application of a
perspective.
These transformations make the
target element and its children
being drawn as a solid, singular
object.
Joshfire

This sample code works for
Safari IOS 5 elements.
The triggers are enginedependent.
-webkit
-transform:
translateZ(0);

!

-webkit
-perspective: 1000;

!

-webkit
-backface
-visibility:

hidden;
OPTIM

ACCELERATE ALL THE THINGS ?

• Accelerating key elements can solve most of the
visual quirks linked to the tiling effect

• It also has significant visual drawbacks

o

o

Accelerated fonts are drawn as images and not the
product of vectorial operations, which cancels antialiasing

Most graphics suffer from the transformation that's
applied to the bitmap, resulting in general
blurriness.
blurriness

Joshfire
OPTIM

CRASHES. CRASHES EVERYWHERE.

• Each "master layer" (i.e.
•
•
•

accelerated elements and grid tiles
— called "Compositing Layer")
draws resources from the GPU
Limited amount of available
memory
Large quantity of accelerated
items tend to overflow the GPUs'
buffers, causing the device to
crash the application
Accelerating only key elements is
a necessity.
Joshfire

Mo

Mo

Mo

Mo
OPTIM

REDRAWS

changes, only the
• When the DOM the modified DOM renderers
associated with
are called
accelerated
• However,their content elements tend to wholly
repaint if
is updated

oThis is due to the fact that the accelerated

element ends up as a "whole" bitmap
Often-changing elements should be
accelerated with caution, they can trigger the
repainting of bigger elements that didn't
need it.
Use chrome's devtools to identify you layers'
behaviour

Regular <div>

Modified

<p>lipsum</p>

o
o
!

that
• Ensuringtick is redraws are notofuselessly heavy
at each
a relevant part optimisation
Joshfire

Accelerated <div>

Modified

<p>lipsum</p>
OPTIM

OTHER FACTORS

• Some properties are naturally GPU-heavy

box-shadow, background-size, text-shadow, reflections,
etc.
o Image shims and server preprocessing can make a
significant difference in rendering at the cost of overall
memory or network transit
Using transitions to create sliding or fading effect also
triggers acceleration
o Avoid redraws during animations
o Animate only the strict minimum visually ; hide out of
bound items, detach unimportant nodes, temporarily
disable shadows/other effects
o

•

Joshfire
OPTIM

BALANCE

• As usual with most things, it's all about balance
• A limited amount of elements should be accelerated to

maximise user experience improvements.
oAccurately select and accelerate elements that are
expected to be tiled or blinking.
oDetach irrelevant elements from the rendering tree ; use
visibility: hidden; to preserve the layout if needed
oDraw a background in a separate, accelerated element :
fewer redraws and no tiling on one of the visually most
important but technically lightweight element.

!

• If these easily applicable (though less easily identifiable)
methods fail, it's time to approach different angles.
Joshfire
DIFFERENT ANGLES
STEP BACK

UMA

mobile
• MostAndroidsdevices (iPhones
and
included) do not
provide dedicated GPU
memory

Heavy Code

!
!

• Unified Memory Architecture
• A pool of memory both GPU
and CPU can access
of the
• Heavy solicitationprocessing
memory via CPU

while ( 1 )

!

{

Infinite movie posters list
scrolling

console.log('derp');

}

(calculations, main routine) will
decrease available memory for
the GPU

• ... and vice versa.
Joshfire

SHARED MEMORY
STANDARD CHECKLIST
• Free up memory
o

Check for memory leaks (which is another
presentation altogether)
o Unload unnecessary collections / templates / etc.
o Chunks of data can be swapped with localstorage
(slow)

!

• Flatten the DOM
o

Minimize pure-layout nodes
o CSS3 — when applicable — enhances pure css
layouting abilities at minimal cost
o Minimize <a>'s, use data-url="" and events instead
Joshfire
DETACHING DOM FRAGMENTS
• DOM subtrees can be kept in memory without being
attached to the main tree


• In this state they stay loaded in memory and parsed
but are excluded from the rendering at every step


• Detaching / Attaching subtrees to the DOM is fairly
fast, as opposed to parsing / loading


• This can be especially effective for scrollview
children...

Joshfire
IMITATING TABLEVIEWS
• Long and rich lists are often the core problem in terms
of performance
• It is often necessary to control the quantity of items
•
•

displayed at once ; the way native SDKs manage table
cells.
Progressively detach / attach elements depending on
the position in the scroll view
Preserve the height of the scrollview with a leading
<div> which can be resized

!

• Quite effective when lines are reasonably light
Joshfire
RENDERING ON CANVASES
• Dense, graphical areas can be rendered onto <canvas> elements
o

Reduces the number of nodes drastically

o

should act as a bitmap once fully drawn

o

Can abstract large rows/columns of images

• Loses any sense of structure ; no more DOM
o

Can impede basic and essential features

• Support still edgy on some devices
!

• Very efficient for dense graphical areas. Can become expensive
in development time.

Joshfire
THIS IS THE END
You are now free to hit ESC.

Weitere ähnliche Inhalte

Ähnlich wie Webapp Rendering and Optimization.

Design4Drupal Boston 2013 - Bumps in the Road to Responsive
Design4Drupal Boston 2013 - Bumps in the Road to ResponsiveDesign4Drupal Boston 2013 - Bumps in the Road to Responsive
Design4Drupal Boston 2013 - Bumps in the Road to Responsive
Salem Ghoweri
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
Andrew Ferrier
 
Talk 03 responsive-web-design
Talk 03 responsive-web-designTalk 03 responsive-web-design
Talk 03 responsive-web-design
Monkeyshot
 
Creating Responsive HTML5 Touch Interfaces
Creating Responsive HTML5 Touch InterfacesCreating Responsive HTML5 Touch Interfaces
Creating Responsive HTML5 Touch Interfaces
Stephen Woods
 
Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
Open Academy
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
Andrew Ferrier
 

Ähnlich wie Webapp Rendering and Optimization. (20)

Design4Drupal Boston 2013 - Bumps in the Road to Responsive
Design4Drupal Boston 2013 - Bumps in the Road to ResponsiveDesign4Drupal Boston 2013 - Bumps in the Road to Responsive
Design4Drupal Boston 2013 - Bumps in the Road to Responsive
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
 
Mobile Best Practices
Mobile Best PracticesMobile Best Practices
Mobile Best Practices
 
From HTML to pixels on the Screen
From HTML to pixels on the ScreenFrom HTML to pixels on the Screen
From HTML to pixels on the Screen
 
Talk 03 responsive-web-design
Talk 03 responsive-web-designTalk 03 responsive-web-design
Talk 03 responsive-web-design
 
iOS App performance - Things to take care
iOS App performance - Things to take careiOS App performance - Things to take care
iOS App performance - Things to take care
 
Creating Responsive HTML5 Touch Interfaces
Creating Responsive HTML5 Touch InterfacesCreating Responsive HTML5 Touch Interfaces
Creating Responsive HTML5 Touch Interfaces
 
Speeding up mobile web apps
Speeding up mobile web appsSpeeding up mobile web apps
Speeding up mobile web apps
 
Browsers. Magic is inside.
Browsers. Magic is inside.Browsers. Magic is inside.
Browsers. Magic is inside.
 
Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
 
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
 
Smooth Animations for Web & Hybrid
Smooth Animations for Web & HybridSmooth Animations for Web & Hybrid
Smooth Animations for Web & Hybrid
 
About Layout in Firefox
About Layout in FirefoxAbout Layout in Firefox
About Layout in Firefox
 
Javascript for Wep Apps
Javascript for Wep AppsJavascript for Wep Apps
Javascript for Wep Apps
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012
 
Running MongoDB in the Cloud
Running MongoDB in the CloudRunning MongoDB in the Cloud
Running MongoDB in the Cloud
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Webapp Rendering and Optimization.

  • 1. Rendering Optimizations A few insights on how to cope with high quality, rich webapps Apr. 2013 Arthur Jamain arthur@joshfire.com
  • 3. CONTEXT TECHNOLOGIES • Rich HTML5/JS Applications expected to behave like a native app. • Basic access to native features • Low resources, high-end display Joshfire
  • 4. CONTEXT OBJECTIVES • High expectations of UX quality • Heavy content : lengthy videos or images lists, overall rich UIs • Animations and multidirectional nested scrolling • Cost effectiveness. Joshfire
  • 5. CONTEXT VALIDITY • Most of the concepts described in this presentation are heavily platform dependent • Rendering engines do implement the same specifications but in different forms, and future evolutions may invalidate this document. • The current (early 2013) implementations of iOS, Android, BB10, Microsoft... devices' default web engines all fit this document Joshfire
  • 7. WEBAPPS RUNTIME • A Native Webview runs the HTML5 App • Alongside are plugins : camera, sensors, etc. • The Webview is entirely opaque to the native runtime o No (native) memory handling / garbage collection o No pre-rendering / dynamic loading / caching of table cells, list views or scroll views o Sparse critical error handling Joshfire
  • 8. WEBAPPS RENDERING • The one Webview's engine renders the whole app o We're talking UI here, it is fairly easy to defer big calculations to native components. • Its size in memory and its resource consumption are "unitary" • It can use the device's processor, RAM and GPU to achieve its rendering process • Decreasing the Webview’s (hence, the app) resource consumption can only be done by altering the JS / CSS / HTML code which determines what is rendered and how. Joshfire
  • 9. PAGE RENDERING In the kingdom of the blind …
  • 10. RENDERING WHAT IS IT ? • The process of JS HTML load, parse transforming the document into what we see on our CSS Alter DOM Tree screen. • Input : DOM (nodes, CSS) • Output : Bitmaps to be Render Tree & Render Layer Tree drawn on the browsers' Rendered Bitmap canvas Joshfire
  • 11. RENDERING THE RENDER TREE • Ordered tree of visual elements (“renderers”) representing the DOM elements • Enables painting the contents in their correct order • DOM Nodes spawn one or more renderers under certain conditions only : display mode, visibility... • Their ordering depends on their box-model settings, sizing rules, etc. • Controlling the size and depth of the render tree allows control of the rendering performances Joshfire
  • 12. RENDERING THE RENDER TREE Check these options in Chrome&Co. to visualize the content rectangles • Each renderer has children renderers • Each renderer draws a rectangle defined by its computed CSS properties and its children’s ones. Joshfire
  • 13. RENDERING LAYERS ! • The browser then draws a • • • grid of rectangles. Controlled-size layers — hence keeping several smaller objects in memory The renderer's rectangles are split among these "master" layers/rectangles These rectangles are then printed as bitmaps on the screen, asynchronously. Note : These layers or tiles are drawn by the GPU Joshfire Html content that spans on the whole page. Note that the grey element is split and drawn among 4 tiles
  • 15. RECAP DOM Tree • Initially, and whenever the drawing loop ticks :! o The DOM nodes that have changed spawn Render Tree and modify renderers accordingly, creating or completing the rendering tree! o Renderers calculate their respective Render Layer Tree (Grid and layers) rectangles and their contents! o These rectangles are projected onto cells of GPU a grid! o Each cell of the grid is drawn as a bitmap on the screen by the GPU Joshfire
  • 17. OPTIM HARDWARE ACCELERATION • Tiling may produce weird • • visual effects o They are drawn on a single thread, asynchronously. o Heavier tiles may be drawn visually significantly after lighter tiles To avoid this, we grant large elements their own "master" layers ! This is what "accelerating" an element refers to. Joshfire The “accelerated” node is drawn as one solid rectangle and is not split
  • 18. OPTIM USING ACCELERATION • Some renderers in the render • • tree can be sent "on top" This happens when an element undergoes one of several transformations — such as a rotation or the application of a perspective. These transformations make the target element and its children being drawn as a solid, singular object. Joshfire This sample code works for Safari IOS 5 elements. The triggers are enginedependent. -webkit -transform: translateZ(0); ! -webkit -perspective: 1000; ! -webkit -backface -visibility: hidden;
  • 19. OPTIM ACCELERATE ALL THE THINGS ? • Accelerating key elements can solve most of the visual quirks linked to the tiling effect • It also has significant visual drawbacks o o Accelerated fonts are drawn as images and not the product of vectorial operations, which cancels antialiasing Most graphics suffer from the transformation that's applied to the bitmap, resulting in general blurriness. blurriness Joshfire
  • 20. OPTIM CRASHES. CRASHES EVERYWHERE. • Each "master layer" (i.e. • • • accelerated elements and grid tiles — called "Compositing Layer") draws resources from the GPU Limited amount of available memory Large quantity of accelerated items tend to overflow the GPUs' buffers, causing the device to crash the application Accelerating only key elements is a necessity. Joshfire Mo Mo Mo Mo
  • 21. OPTIM REDRAWS changes, only the • When the DOM the modified DOM renderers associated with are called accelerated • However,their content elements tend to wholly repaint if is updated oThis is due to the fact that the accelerated element ends up as a "whole" bitmap Often-changing elements should be accelerated with caution, they can trigger the repainting of bigger elements that didn't need it. Use chrome's devtools to identify you layers' behaviour Regular <div> Modified <p>lipsum</p> o o ! that • Ensuringtick is redraws are notofuselessly heavy at each a relevant part optimisation Joshfire Accelerated <div> Modified <p>lipsum</p>
  • 22. OPTIM OTHER FACTORS • Some properties are naturally GPU-heavy box-shadow, background-size, text-shadow, reflections, etc. o Image shims and server preprocessing can make a significant difference in rendering at the cost of overall memory or network transit Using transitions to create sliding or fading effect also triggers acceleration o Avoid redraws during animations o Animate only the strict minimum visually ; hide out of bound items, detach unimportant nodes, temporarily disable shadows/other effects o • Joshfire
  • 23. OPTIM BALANCE • As usual with most things, it's all about balance • A limited amount of elements should be accelerated to maximise user experience improvements. oAccurately select and accelerate elements that are expected to be tiled or blinking. oDetach irrelevant elements from the rendering tree ; use visibility: hidden; to preserve the layout if needed oDraw a background in a separate, accelerated element : fewer redraws and no tiling on one of the visually most important but technically lightweight element. ! • If these easily applicable (though less easily identifiable) methods fail, it's time to approach different angles. Joshfire
  • 25. STEP BACK UMA mobile • MostAndroidsdevices (iPhones and included) do not provide dedicated GPU memory Heavy Code ! ! • Unified Memory Architecture • A pool of memory both GPU and CPU can access of the • Heavy solicitationprocessing memory via CPU while ( 1 ) ! { Infinite movie posters list scrolling console.log('derp'); } (calculations, main routine) will decrease available memory for the GPU • ... and vice versa. Joshfire SHARED MEMORY
  • 26. STANDARD CHECKLIST • Free up memory o Check for memory leaks (which is another presentation altogether) o Unload unnecessary collections / templates / etc. o Chunks of data can be swapped with localstorage (slow) ! • Flatten the DOM o Minimize pure-layout nodes o CSS3 — when applicable — enhances pure css layouting abilities at minimal cost o Minimize <a>'s, use data-url="" and events instead Joshfire
  • 27. DETACHING DOM FRAGMENTS • DOM subtrees can be kept in memory without being attached to the main tree • In this state they stay loaded in memory and parsed but are excluded from the rendering at every step • Detaching / Attaching subtrees to the DOM is fairly fast, as opposed to parsing / loading • This can be especially effective for scrollview children... Joshfire
  • 28. IMITATING TABLEVIEWS • Long and rich lists are often the core problem in terms of performance • It is often necessary to control the quantity of items • • displayed at once ; the way native SDKs manage table cells. Progressively detach / attach elements depending on the position in the scroll view Preserve the height of the scrollview with a leading <div> which can be resized ! • Quite effective when lines are reasonably light Joshfire
  • 29. RENDERING ON CANVASES • Dense, graphical areas can be rendered onto <canvas> elements o Reduces the number of nodes drastically o should act as a bitmap once fully drawn o Can abstract large rows/columns of images • Loses any sense of structure ; no more DOM o Can impede basic and essential features • Support still edgy on some devices ! • Very efficient for dense graphical areas. Can become expensive in development time. Joshfire
  • 30. THIS IS THE END You are now free to hit ESC.