SlideShare a Scribd company logo
HTML version of slides: http://people.mozilla.org/~bbirtles/pres/graphical-web-2014/
Animations on Fire - Making Web animations fast
Animations can be used for more than just cat gifs. 
They can be used to tell stories too.
Animation is essentially about using time 
to convey information.
Animation can be used as component of user interface design to describe the results of an action.
It can be more intuitive without cluttering the screen or requiring extra explanation.
But when animation runs slowly or hesitates, that information is lost. 
Hence for animation, performance is critical. 
In order to fix animation performance in Web pages, we really need to understand how browsers work.
As we follow the journey from markup to our eyeballs, we will consider how we can make each step smoother or skip it all together.
Animations on Fire - Making Web animations fast
Parsing can be slow. Most browsers do it in a separate thread. 
If we skip parsing while animating surely it goes faster?
A micro-benchmark suggests an API that skips parsing is faster.
How about in a real-world animation?
It doesn’t make a lot of difference. Perhaps 3~4 fps at best.
Animations on Fire - Making Web animations fast
There are bigger performance gains to be had from the style system. 
After creating a DOM tree, browsers construct a render tree suitable for painting to the screen.
What happens if we exploit the fact that display:none elements don’t appear in the render tree?
Animations on Fire - Making Web animations fast
(Firefox doesn’t show such a big difference in this case since the test case animates ‘top’ which, as we’ll see, does not trigger reflow in Firefox so setting display:none doesn’t have as big an impact.)
This technique improved performance for the Parapara animation project where characters are set to display:none when they are off-stage.
Of the operations performed in the style system, the layout/reflow step is often expensive.
We can measure style resolution and layout time in profiling tools in Firefox (above) and Chrome (below).
Firefox lets you inspect reflow (layout) in the console.
Let’s see how different animations affect layout
Animating margin-top causes reflow on every frame
But in Firefox, animating top or transform does not trigger reflow (layout)
Animations on Fire - Making Web animations fast
Comparing the performance of margin-top and transform, transform is faster because it avoids reflow but it also benefits from layerization which we will see later.
Animations on Fire - Making Web animations fast
Since these processes can be expensive, browsers avoid doing them until either they have to paint, or until script asks a question about the current state.
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Painting is often the most expensive part. Firefox creates a display list of items to paint, then creates a layer tree into which it paints. The layers in the tree are then composited together.
Animations on Fire - Making Web animations fast
We can see exactly what area is being painted
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
When animating transform we only paint once at the start. 
This is because it gets put in its own layer.
When animating independent areas Chrome seems to paint the union of dirty areas so layerization can be more important there.
However, SVG filters are often hardware accelerated. 
Sometimes the combination of features is what is slow.
Animations on Fire - Making Web animations fast
We can sometimes make things faster by pre-rendering. 
Desktop apps, native apps, Flash apps, everyone does it.
Alternatively, for SVG, simply referring to the SVG using <img> instead of <iframe> lets the browser make more optimizations. Especially Firefox.
Most browsers hardware accelerate layer compositing. 
That means they can often paint an animated element once then just change its transform, opacity etc. and let the GPU re-composite. 
That saves a lot of painting.
It’s up to the browser what gets a layer. 
Typically it’s things like the above.
Animations on Fire - Making Web animations fast
Firefox OS
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
In the previous example, we can see why the transform animation only gets painted once. That element has its own layer.
Layerization is performed by the browser so it can automatically do it for SVG (SMIL) animation too.
And even for scripted animation, the browser can detect that an element is moving a lot and decide it would benefit from being on a separate layer. 
(The red boxes in this example indicate image layers.)
Often, however, the browser won’t create a layer until an element starts animating. Sometimes that can be too late and can cause the animation to stutter at the start as the browser sets up the layer.
will-change:transform/ opacity/etc. lets the browser create the layer in advance if it thinks that would help improve performance. 
transform:translateZ(0) doesn’t work cross- browser
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Apart from low frame-rates, animation performance is affected by other processes on the same thread like layout, garbage collection, or other scripts, that cause the animation to stop and start (jank).
To avoid jank, some animations can be run on a separate thread/process.
Unlike animations running on the main thread which stop and start…
… these animations continue along uninterrupted.
But not everything can be animated in this way. 
In particular, when the browser doesn’t know all the parameters of the animation—like most scripted animations—the browser can’t delegate the animation to another thread/process.
One way around this is to use the Web Animations API to create animations. 
This lets the browser optimize the animation in the same way as it does for declarative animations like CSS Animations/Transitions.
Summarizing our journey…
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Animations on Fire - Making Web animations fast
Using our knowledge of how browsers work we can make animations that run smoothly on any browser on any device and convey their intended effect.
HTML version of slides: http://people.mozilla.org/~bbirtles/pres/graphical-web-2014/

More Related Content

PDF
Remote Method Invocation, Advanced programming
PDF
SharePointアドイン開発 Line風Chat アドイン
PPTX
Programming in Java
PPTX
Automation Test Framework
PDF
Performance testing of mobile apps
PDF
Deep Dive async/await in Unity with UniTask(EN)
PDF
Java presentation
PDF
오픈 소스를 활용한 캐쥬얼 게임 서버 프레임워크 개발
Remote Method Invocation, Advanced programming
SharePointアドイン開発 Line風Chat アドイン
Programming in Java
Automation Test Framework
Performance testing of mobile apps
Deep Dive async/await in Unity with UniTask(EN)
Java presentation
오픈 소스를 활용한 캐쥬얼 게임 서버 프레임워크 개발

What's hot (20)

PPTX
Scientific calcultor-Java
PDF
Appium: Automation for Mobile Apps
PPT
Android software stack
DOCX
Ni labview y multisim
PPTX
Android testing
PPT
Debugging
PDF
Introduction to kotlin
PDF
2015-StarWest presentation on REST-assured
PPTX
Cucumber BDD
PPTX
Java 101
PDF
게임사를 위한 Amazon GameLift 세션 - 이정훈, AWS 솔루션즈 아키텍트
PPTX
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
PPTX
Selenium Tutorial Java
PDF
An Introduction to Test Driven Development
KEY
Django Celery
PDF
Agile Simplified
PPTX
The history of selenium
PPTX
android sqlite
PPTX
An overview of selenium webdriver
PDF
.NET Core, ASP.NET Core Course, Session 6
Scientific calcultor-Java
Appium: Automation for Mobile Apps
Android software stack
Ni labview y multisim
Android testing
Debugging
Introduction to kotlin
2015-StarWest presentation on REST-assured
Cucumber BDD
Java 101
게임사를 위한 Amazon GameLift 세션 - 이정훈, AWS 솔루션즈 아키텍트
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
Selenium Tutorial Java
An Introduction to Test Driven Development
Django Celery
Agile Simplified
The history of selenium
android sqlite
An overview of selenium webdriver
.NET Core, ASP.NET Core Course, Session 6
Ad

Viewers also liked (20)

PDF
Logiciel diagramme
PDF
Serious Animation (an introduction to Web Animations)
PPTX
Vision 2030: Gauteng Provincial Fire & Rescue Services - RG Hendricks
PDF
2015 Land Markets Survey | REALTORS Land Institute & NAR
PDF
2014 Land Markets Survey
PDF
Tablas de contenidos
PDF
El sindrome del Impostor - ¿Incapacidad o Pobre Imagen de sí mismo/a?
PDF
11 Of The Oddest Pets You Might Want To Look After
PDF
Erik Proposal Final
PDF
reshma resume
PDF
Lodgement Order dated 28.01.2017 of Registrar Supreme Court of India
PDF
vJUG - The JavaFX Ecosystem
PDF
Open Source - Hip not Hype
PDF
プリンより滑らか。スムーズなアニメーションの作り方
PDF
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
PDF
Pubcon 2016 - How SEO's can Use PPC to hit their goals
PPTX
ARTIFICIAL RETINA/EYE (ASR,BIONIC EYE)
PDF
Marco Gold Standard
PDF
L'Instrumentation des Bâtiments_LQE
PPTX
2016 Land Markets Survey
Logiciel diagramme
Serious Animation (an introduction to Web Animations)
Vision 2030: Gauteng Provincial Fire & Rescue Services - RG Hendricks
2015 Land Markets Survey | REALTORS Land Institute & NAR
2014 Land Markets Survey
Tablas de contenidos
El sindrome del Impostor - ¿Incapacidad o Pobre Imagen de sí mismo/a?
11 Of The Oddest Pets You Might Want To Look After
Erik Proposal Final
reshma resume
Lodgement Order dated 28.01.2017 of Registrar Supreme Court of India
vJUG - The JavaFX Ecosystem
Open Source - Hip not Hype
プリンより滑らか。スムーズなアニメーションの作り方
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Pubcon 2016 - How SEO's can Use PPC to hit their goals
ARTIFICIAL RETINA/EYE (ASR,BIONIC EYE)
Marco Gold Standard
L'Instrumentation des Bâtiments_LQE
2016 Land Markets Survey
Ad

Similar to Animations on Fire - Making Web animations fast (20)

PPTX
PG Day Us: Animations for Web & Hybrid
PDF
Smooth Animations for Web & Hybrid
PDF
Fullstack 2018 - Fast but not furious: debugging user interaction performanc...
PDF
Performance.now() fast but not furious
PPTX
Fastest css3 animations
PDF
Performance beyond page load - CSS Conf Asia 2015
PDF
Make Your Animations Perform Well - JS Conf Budapest 2017
PDF
Make your animations perform well - Anna Migas - Codemotion Rome 2017
PDF
Make your animations perform well
PDF
Fast but not furious: debugging user interaction performance issues
PDF
Css3 transitions and animations + graceful degradation with jQuery
PDF
HalfStack fast but not furious
PPTX
Javascript Animation with Canvas - Gregory Starr 2015
PDF
NordicJS: Fast but not Furious: Debugging User Interaction Performance Issues
PDF
Web Zurich - Make your animations perform well
PDF
Choosing your animation adventure - Generate NYC 2018
PDF
Performance (browser)
PPTX
Web performance
PDF
Are We Fast Yet? HTML & Javascript Performance - UtahJS
PDF
HalfStack London - Make Your Animations Perform Well
PG Day Us: Animations for Web & Hybrid
Smooth Animations for Web & Hybrid
Fullstack 2018 - Fast but not furious: debugging user interaction performanc...
Performance.now() fast but not furious
Fastest css3 animations
Performance beyond page load - CSS Conf Asia 2015
Make Your Animations Perform Well - JS Conf Budapest 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well
Fast but not furious: debugging user interaction performance issues
Css3 transitions and animations + graceful degradation with jQuery
HalfStack fast but not furious
Javascript Animation with Canvas - Gregory Starr 2015
NordicJS: Fast but not Furious: Debugging User Interaction Performance Issues
Web Zurich - Make your animations perform well
Choosing your animation adventure - Generate NYC 2018
Performance (browser)
Web performance
Are We Fast Yet? HTML & Javascript Performance - UtahJS
HalfStack London - Make Your Animations Perform Well

Recently uploaded (20)

PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
innovation process that make everything different.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
Digital Literacy And Online Safety on internet
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
artificial intelligence overview of it and more
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Introduction to the IoT system, how the IoT system works
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Funds Management Learning Material for Beg
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Testing WebRTC applications at scale.pdf
SASE Traffic Flow - ZTNA Connector-1.pdf
522797556-Unit-2-Temperature-measurement-1-1.pptx
Introduction to Information and Communication Technology
international classification of diseases ICD-10 review PPT.pptx
innovation process that make everything different.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Digital Literacy And Online Safety on internet
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
An introduction to the IFRS (ISSB) Stndards.pdf
artificial intelligence overview of it and more
Tenda Login Guide: Access Your Router in 5 Easy Steps
Introuction about WHO-FIC in ICD-10.pptx
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Introduction to the IoT system, how the IoT system works
The Internet -By the Numbers, Sri Lanka Edition
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
RPKI Status Update, presented by Makito Lay at IDNOG 10
Funds Management Learning Material for Beg
Sims 4 Historia para lo sims 4 para jugar
Testing WebRTC applications at scale.pdf

Animations on Fire - Making Web animations fast

  • 1. HTML version of slides: http://people.mozilla.org/~bbirtles/pres/graphical-web-2014/
  • 3. Animations can be used for more than just cat gifs. They can be used to tell stories too.
  • 4. Animation is essentially about using time to convey information.
  • 5. Animation can be used as component of user interface design to describe the results of an action.
  • 6. It can be more intuitive without cluttering the screen or requiring extra explanation.
  • 7. But when animation runs slowly or hesitates, that information is lost. Hence for animation, performance is critical. In order to fix animation performance in Web pages, we really need to understand how browsers work.
  • 8. As we follow the journey from markup to our eyeballs, we will consider how we can make each step smoother or skip it all together.
  • 10. Parsing can be slow. Most browsers do it in a separate thread. If we skip parsing while animating surely it goes faster?
  • 11. A micro-benchmark suggests an API that skips parsing is faster.
  • 12. How about in a real-world animation?
  • 13. It doesn’t make a lot of difference. Perhaps 3~4 fps at best.
  • 15. There are bigger performance gains to be had from the style system. After creating a DOM tree, browsers construct a render tree suitable for painting to the screen.
  • 16. What happens if we exploit the fact that display:none elements don’t appear in the render tree?
  • 18. (Firefox doesn’t show such a big difference in this case since the test case animates ‘top’ which, as we’ll see, does not trigger reflow in Firefox so setting display:none doesn’t have as big an impact.)
  • 19. This technique improved performance for the Parapara animation project where characters are set to display:none when they are off-stage.
  • 20. Of the operations performed in the style system, the layout/reflow step is often expensive.
  • 21. We can measure style resolution and layout time in profiling tools in Firefox (above) and Chrome (below).
  • 22. Firefox lets you inspect reflow (layout) in the console.
  • 23. Let’s see how different animations affect layout
  • 24. Animating margin-top causes reflow on every frame
  • 25. But in Firefox, animating top or transform does not trigger reflow (layout)
  • 27. Comparing the performance of margin-top and transform, transform is faster because it avoids reflow but it also benefits from layerization which we will see later.
  • 29. Since these processes can be expensive, browsers avoid doing them until either they have to paint, or until script asks a question about the current state.
  • 33. Painting is often the most expensive part. Firefox creates a display list of items to paint, then creates a layer tree into which it paints. The layers in the tree are then composited together.
  • 35. We can see exactly what area is being painted
  • 38. When animating transform we only paint once at the start. This is because it gets put in its own layer.
  • 39. When animating independent areas Chrome seems to paint the union of dirty areas so layerization can be more important there.
  • 40. However, SVG filters are often hardware accelerated. Sometimes the combination of features is what is slow.
  • 42. We can sometimes make things faster by pre-rendering. Desktop apps, native apps, Flash apps, everyone does it.
  • 43. Alternatively, for SVG, simply referring to the SVG using <img> instead of <iframe> lets the browser make more optimizations. Especially Firefox.
  • 44. Most browsers hardware accelerate layer compositing. That means they can often paint an animated element once then just change its transform, opacity etc. and let the GPU re-composite. That saves a lot of painting.
  • 45. It’s up to the browser what gets a layer. Typically it’s things like the above.
  • 50. In the previous example, we can see why the transform animation only gets painted once. That element has its own layer.
  • 51. Layerization is performed by the browser so it can automatically do it for SVG (SMIL) animation too.
  • 52. And even for scripted animation, the browser can detect that an element is moving a lot and decide it would benefit from being on a separate layer. (The red boxes in this example indicate image layers.)
  • 53. Often, however, the browser won’t create a layer until an element starts animating. Sometimes that can be too late and can cause the animation to stutter at the start as the browser sets up the layer.
  • 54. will-change:transform/ opacity/etc. lets the browser create the layer in advance if it thinks that would help improve performance. transform:translateZ(0) doesn’t work cross- browser
  • 58. Apart from low frame-rates, animation performance is affected by other processes on the same thread like layout, garbage collection, or other scripts, that cause the animation to stop and start (jank).
  • 59. To avoid jank, some animations can be run on a separate thread/process.
  • 60. Unlike animations running on the main thread which stop and start…
  • 61. … these animations continue along uninterrupted.
  • 62. But not everything can be animated in this way. In particular, when the browser doesn’t know all the parameters of the animation—like most scripted animations—the browser can’t delegate the animation to another thread/process.
  • 63. One way around this is to use the Web Animations API to create animations. This lets the browser optimize the animation in the same way as it does for declarative animations like CSS Animations/Transitions.
  • 69. Using our knowledge of how browsers work we can make animations that run smoothly on any browser on any device and convey their intended effect.
  • 70. HTML version of slides: http://people.mozilla.org/~bbirtles/pres/graphical-web-2014/