SlideShare ist ein Scribd-Unternehmen logo
1 von 33
1
Optimizing Browser DOM
Rendering
Michael Labriola - @mlabriola
Senior Consultant w/ Digital Primates
Session Expectations - Performance
This session is about performance optimization but it‟s not
an absolute thing.
Performance has both subjective and absolute aspects
• Perceived performance can be the difference between a
user‟s willingness to use an application or abandon it
• Raw computational work may decide which devices can use
your work effectively and for how long
2
Session Expectations - Optimization
Performance Optimization is similarly difficult.
• An optimization in one situation can unintentionally degrade
performance in another
• Optimization is more about understanding a range of
possibilities and trying to find the sweet spot for your purpose
Performance advice is usually about what to do, but it‟s
contextual.
• Context is just often lost in the explanation.
• Performance related advice can often appear conflicting
• There are exceptions
• Much of the advice you can find online is out of date
3
Session Expectations - Goal
This presentation is about understanding the browser
• Understanding internals helps you build a mental model
• The real goal is to know why to do something
This is a big topic that we could talk about for days.
Alas, we have an hour, so:
• I won‟t get to cover everything I want
• I won‟t get to dive into the depth that I desire
• This is my best to balance at a lot of theory and practical ways
to apply
4
Disclaimer
Unfortunately, with this type of technical content I need a
disclaimer.
Applicability
• This advice is generally for Webkit-based rendering
• Most of it is identical for Gecko (Firefox), although some of the
terminology is different
• Internet Explorer
• Most of the general advice is still valid for IE
• There are major differences in the way IE7, IE8 and IE9 handle
some of these things
• I am not saying to ignore IE. The general advice is good and
then its worth while to experiment and test on IE.
5
Jumping In
When you navigate to a URL, a web page is loaded by a
Loader. Let‟s call the result of that load operation „tag soup‟
for now.
Tag soup needs to get parsed
6
The goal of the parsing step is to create something we call
the DOM tree. In a perfect world it might look like this:
Parsing
7
<html>
<head>
<title>Yo!</title>
</head>
<body>
<div>
<img src="ncdev.jpg">
</div>
<div><p>Dev Con</p></div>
</body>
</html>
Parsing – Best Guess
Unfortunately HTML isn‟t always perfect, so the parser has
to make some best guesses and try to bring something
together:
8
<html>
<head>
<title>Yo!</title>
</head>
<body>
<div>
<img src="ncdev.jpg">
</div>
<div><p>Dev Con
</body>
</html>
Parsing – Best Guess Gone Wrong
..and those guesses may not be what you expected. So,
validate your HTML, save the parser some effort and you
some sanity.
9
<html>
<head>
<title>Yo!</title>
</head>
<body>
<div>
<img src="ncdev.jpg">
<div><p>Dev Con
</body>
</html>
Waterfall
Modern browsers do some optimistic look-aheads, if the
parser is ever blocked/waiting, the browser begins
downloading other external content it will also need
10
CSS
The combination of default style sheets, inline styles, inline
CSS and CSS Loaded from external files provides
information we use for layout and styling. So, we build a tree
(actually a few and some more data structures)
11
p,div{
margin-top:3px;
}
.error {
color:red;
}
DOM and CSS sitting in a Tree
Information from the DOM tree and the Style Structures are
used to form the Render Tree. The Render Tree holds the
information about what gets painted on the screen.
12
CSS Style Matching
CSS styles are stored into various maps so that they can be
easily retrieved later.
13
div {
font-size: 11pt;
}
table div {
font-size: 12pt;
}
#theId {
display: none;
}
.myClass {
color: #ff0000;
}
Tag
ID
Class
<div>
<img src="foo.jpg">
</div>
<div>
<p>NCDev</p>
</div>
<p id="theId"></p>
<p class="myClass"></p>
Quick Advice on CSS
Specificity is important, but the rule be as specific as
possible is confusing. From a pure performance standpoint
• ID Selectors followed by Class Selectors are very fast
• Further clarifying these is NOT helpful, its slower
p.myClass table#thingy
• Descendant Selectors and Child Selectors should be avoided
whenever humanly possible
.myul_in_a_div {}
versus
ul div {}
14
CSS Caveats
Caveats - How specific a selector is determines its weight
when styles cascade
• It‟s from is a 'style' attribute rather than a rule with a selector
• The number of ID attributes in the selector
• The number of other attributes and pseudo-classes in the
selector
• The number of element names and pseudo-elements in the
selector
15
Understanding the Render Tree
The render tree is about the visual aspects of your display
16
div {
font-size: 11pt;
}
img {
display: none;
}
Putting it all together
Manipulating the DOM is the slowest thing we can do in the
web environment. Depending on what we do, the browser
needs to mark things as invalid. The process of making
them valid again means executing parts of this diagram.
17
Repaint Only
If we are careful and just make changes to things like color,
visibility or other changes that don‟t require new
measurement and layout, we can often just execute this part
of the chart:
18
Re-layout/Flow
If we make any change that requires that causes a size or
positioning difference we need to minimally executed these
parts of the chart.
19
Do Less Work
The simple truth behind making DOM interactions faster is
to do less of it…
A few ways to do less
• Execute the smallest amount of that flow chart that you can at
any time
• Actively worry if your choices make the browser execute any
part of it multiple times in a row
• Pay attention to how much of the trees your impacting
• Do your best to let the browser do this work when it is ready
20
Tooling
There are many excellent tools you can use to debug and
look into the information we are about to discuss. We are
just going to use Chrome‟s built in tooling for the moment,
but here are some resources:
21
 YSlow
 Chrome Plugin
 Firefox
 Speed Tracer
 Chrome Plugin
 FireBug
 Firefox
 dynaTrace (5 day
trial)
 IE Extension
 Firefox
 jsPerf
 Webpagetest.org
 (More every 5
minutes)
Chrome‟s Tools
Chrome has a great set of tools that will get us started and
they are all built in
Tools
• Network View
• Timeline
• CSS Profiler
22
Render Information
• Paint Rectangles
• Composited Layer Borders
• FPS Meter
• Continuous Page Repainting
Example 1 – Sized versus Non-Sized
Regions/Images
Really old statement everyone knows:
• Whenever possible, you should provide a width and
height for your images
Why?
23
Example 2 – Visibility versus Display None
Performance Statement:
• You should/shouldn‟t use visibility/display none when you
want to hide something.
Why?
24
Example 3 – Synchronous Layout
Performance Statement:
• You need to batch your changes to the DOM. Always try
to make a single class change versus multiple changes.
Why?
25
Example 4 – Off Dom Manipulation
Performance Statement:
• If you have to make DOM changes, you should make
them „off dom‟
Why?
26
Do Less Work Sooner
The perceived responsiveness of your page/application also
depends on how quickly it starts up.
This ultimately comes down to a few factors
• How much do we need to load on startup?
• How quickly can we load it?
• How much work must we do when everything arrives?
27
Example 6 – CSS Serial Loading
Performance Statement:
• Using CSS @import can slow down your page load
Why?
28
Example 7 – CSS Media Queries
Performance Statement:
• CSS Media Queries are good/bad for performance
Why?
29
Example 8 – Forced Synchronous Loading
Performance Statement:
• The order between external CSS and external Scripts in
the browser can have major performance implications
Why?
30
Example 9 – Script Placement
Performance Statement:
• Your scripts need to be at the top/bottom of your page at
all times.
Why?
31
Selected Resources
WebCore Rendering – Parts I through IV
https://www.webkit.org/blog/114/webcore-rendering-i-the-basics/
How Browsers Work: Behind the scenes of modern web browsers
http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/
Grosskurth, Alan. A Reference Architecture for Web Browsers
http://grosskurth.ca/papers/browser-refarch.pdf
The new game show: “Will it reflow?”
http://www.phpied.com/the-new-game-show-will-it-reflow/
…more to be posted…
32
33
Optimizing Browser DOM
Rendering
Michael Labriola - @mlabriola
Senior Consultant w/ Digital Primates

Weitere ähnliche Inhalte

Was ist angesagt?

We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application developmentWe4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT Group
 
SharePoint 2010 Web Standards & Accessibility
SharePoint 2010 Web Standards & AccessibilitySharePoint 2010 Web Standards & Accessibility
SharePoint 2010 Web Standards & Accessibility
Mavention
 
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
Klaus Bild
 

Was ist angesagt? (20)

XPages Workshop: Customizing OneUI
XPages Workshop: Customizing OneUIXPages Workshop: Customizing OneUI
XPages Workshop: Customizing OneUI
 
Wireless Wednesdays: Part 4
Wireless Wednesdays: Part 4Wireless Wednesdays: Part 4
Wireless Wednesdays: Part 4
 
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
 
Twelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPagesTwelve Tasks Made Easier with IBM Domino XPages
Twelve Tasks Made Easier with IBM Domino XPages
 
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application developmentWe4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
 
Presenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View ControlPresenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View Control
 
Building DotNetNuke Modules
Building DotNetNuke ModulesBuilding DotNetNuke Modules
Building DotNetNuke Modules
 
Becoming an IBM Connections Developer
Becoming an IBM Connections DeveloperBecoming an IBM Connections Developer
Becoming an IBM Connections Developer
 
Using Features
Using FeaturesUsing Features
Using Features
 
SharePoint 2010 Web Standards & Accessibility
SharePoint 2010 Web Standards & AccessibilitySharePoint 2010 Web Standards & Accessibility
SharePoint 2010 Web Standards & Accessibility
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
JMP402 Master Class: Managed beans and XPages: Your Time Is Now
JMP402 Master Class: Managed beans and XPages: Your Time Is NowJMP402 Master Class: Managed beans and XPages: Your Time Is Now
JMP402 Master Class: Managed beans and XPages: Your Time Is Now
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java Application
 
XPages: No Experience Needed
XPages: No Experience NeededXPages: No Experience Needed
XPages: No Experience Needed
 
Meet Magento Belarus 2015: Mladen Ristić
Meet Magento Belarus 2015: Mladen RistićMeet Magento Belarus 2015: Mladen Ristić
Meet Magento Belarus 2015: Mladen Ristić
 
An Overview Of Wpf
An Overview Of WpfAn Overview Of Wpf
An Overview Of Wpf
 
HTML5
HTML5 HTML5
HTML5
 
Mobilize Your Business, Not Just an App
Mobilize Your Business, Not Just an AppMobilize Your Business, Not Just an App
Mobilize Your Business, Not Just an App
 
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
SHOW301 - Make Your IBM Connections Deployment Your Own: Customize It!
 
IBM Presents the Notes Domino Roadmap and a Deep Dive into Feature Pack 8
IBM Presents the Notes Domino Roadmap and a Deep Dive into Feature Pack 8IBM Presents the Notes Domino Roadmap and a Deep Dive into Feature Pack 8
IBM Presents the Notes Domino Roadmap and a Deep Dive into Feature Pack 8
 

Ähnlich wie Optimizing Browser Rendering

Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client Performance
Herea Adrian
 

Ähnlich wie Optimizing Browser Rendering (20)

SMX_DevTools_Monaco_2.pdf
SMX_DevTools_Monaco_2.pdfSMX_DevTools_Monaco_2.pdf
SMX_DevTools_Monaco_2.pdf
 
A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5A modern architecturereview–usingcodereviewtools-ver-3.5
A modern architecturereview–usingcodereviewtools-ver-3.5
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuning
 
How to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fpsHow to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fps
 
Improving frontend performance
Improving frontend performanceImproving frontend performance
Improving frontend performance
 
Web Components
Web ComponentsWeb Components
Web Components
 
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEAEdge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
 
Grokking TechTalk #16: Html js and three way binding
Grokking TechTalk #16: Html js and three way bindingGrokking TechTalk #16: Html js and three way binding
Grokking TechTalk #16: Html js and three way binding
 
Managing the Complexities of Conversion to S1000D
Managing the Complexities of Conversion to S1000DManaging the Complexities of Conversion to S1000D
Managing the Complexities of Conversion to S1000D
 
Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An Overview
 
Performace optimization (increase website speed)
Performace optimization (increase website speed)Performace optimization (increase website speed)
Performace optimization (increase website speed)
 
Evolutionary software design
Evolutionary software designEvolutionary software design
Evolutionary software design
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
Front End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdfFront End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdf
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client Performance
 
11 Amazing things I Learnt At Word Camp Sydney 2014
11 Amazing things I Learnt At Word Camp Sydney 201411 Amazing things I Learnt At Word Camp Sydney 2014
11 Amazing things I Learnt At Word Camp Sydney 2014
 
XPages Blast - Ideas, Tips and More
XPages Blast - Ideas, Tips and MoreXPages Blast - Ideas, Tips and More
XPages Blast - Ideas, Tips and More
 
Choices for Responsive Redesign: Ground-up or Responsive Retrofit
Choices for Responsive Redesign: Ground-up or Responsive RetrofitChoices for Responsive Redesign: Ground-up or Responsive Retrofit
Choices for Responsive Redesign: Ground-up or Responsive Retrofit
 

Mehr von michael.labriola

Developing for a world wide audience
Developing for a world wide audienceDeveloping for a world wide audience
Developing for a world wide audience
michael.labriola
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructure
michael.labriola
 

Mehr von michael.labriola (19)

L2624 labriola
L2624 labriolaL2624 labriola
L2624 labriola
 
Talking trash
Talking trashTalking trash
Talking trash
 
Flex 4 components from the firehose
Flex 4 components from the firehoseFlex 4 components from the firehose
Flex 4 components from the firehose
 
Developing for a world wide audience
Developing for a world wide audienceDeveloping for a world wide audience
Developing for a world wide audience
 
Developing for a world wide audience
Developing for a world wide audienceDeveloping for a world wide audience
Developing for a world wide audience
 
FlexUnit 4 for contributors
FlexUnit 4 for contributorsFlexUnit 4 for contributors
FlexUnit 4 for contributors
 
Write once... Take Less Time to Deploy
Write once... Take Less Time to Deploy Write once... Take Less Time to Deploy
Write once... Take Less Time to Deploy
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Apocalypse Soon
Apocalypse SoonApocalypse Soon
Apocalypse Soon
 
Flex 4 Component Development
Flex 4 Component DevelopmentFlex 4 Component Development
Flex 4 Component Development
 
Any Which Array But Loose
Any Which Array But LooseAny Which Array But Loose
Any Which Array But Loose
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Air Drag And Drop
Air Drag And DropAir Drag And Drop
Air Drag And Drop
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructure
 
Blaze Ds Slides
Blaze Ds SlidesBlaze Ds Slides
Blaze Ds Slides
 
2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Components2007 Max Presentation - Creating Custom Flex Components
2007 Max Presentation - Creating Custom Flex Components
 
Dense And Hot 360 Flex
Dense And Hot 360 FlexDense And Hot 360 Flex
Dense And Hot 360 Flex
 
Dense And Hot Web Du
Dense And Hot  Web DuDense And Hot  Web Du
Dense And Hot Web Du
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 

Optimizing Browser Rendering

  • 1. 1 Optimizing Browser DOM Rendering Michael Labriola - @mlabriola Senior Consultant w/ Digital Primates
  • 2. Session Expectations - Performance This session is about performance optimization but it‟s not an absolute thing. Performance has both subjective and absolute aspects • Perceived performance can be the difference between a user‟s willingness to use an application or abandon it • Raw computational work may decide which devices can use your work effectively and for how long 2
  • 3. Session Expectations - Optimization Performance Optimization is similarly difficult. • An optimization in one situation can unintentionally degrade performance in another • Optimization is more about understanding a range of possibilities and trying to find the sweet spot for your purpose Performance advice is usually about what to do, but it‟s contextual. • Context is just often lost in the explanation. • Performance related advice can often appear conflicting • There are exceptions • Much of the advice you can find online is out of date 3
  • 4. Session Expectations - Goal This presentation is about understanding the browser • Understanding internals helps you build a mental model • The real goal is to know why to do something This is a big topic that we could talk about for days. Alas, we have an hour, so: • I won‟t get to cover everything I want • I won‟t get to dive into the depth that I desire • This is my best to balance at a lot of theory and practical ways to apply 4
  • 5. Disclaimer Unfortunately, with this type of technical content I need a disclaimer. Applicability • This advice is generally for Webkit-based rendering • Most of it is identical for Gecko (Firefox), although some of the terminology is different • Internet Explorer • Most of the general advice is still valid for IE • There are major differences in the way IE7, IE8 and IE9 handle some of these things • I am not saying to ignore IE. The general advice is good and then its worth while to experiment and test on IE. 5
  • 6. Jumping In When you navigate to a URL, a web page is loaded by a Loader. Let‟s call the result of that load operation „tag soup‟ for now. Tag soup needs to get parsed 6
  • 7. The goal of the parsing step is to create something we call the DOM tree. In a perfect world it might look like this: Parsing 7 <html> <head> <title>Yo!</title> </head> <body> <div> <img src="ncdev.jpg"> </div> <div><p>Dev Con</p></div> </body> </html>
  • 8. Parsing – Best Guess Unfortunately HTML isn‟t always perfect, so the parser has to make some best guesses and try to bring something together: 8 <html> <head> <title>Yo!</title> </head> <body> <div> <img src="ncdev.jpg"> </div> <div><p>Dev Con </body> </html>
  • 9. Parsing – Best Guess Gone Wrong ..and those guesses may not be what you expected. So, validate your HTML, save the parser some effort and you some sanity. 9 <html> <head> <title>Yo!</title> </head> <body> <div> <img src="ncdev.jpg"> <div><p>Dev Con </body> </html>
  • 10. Waterfall Modern browsers do some optimistic look-aheads, if the parser is ever blocked/waiting, the browser begins downloading other external content it will also need 10
  • 11. CSS The combination of default style sheets, inline styles, inline CSS and CSS Loaded from external files provides information we use for layout and styling. So, we build a tree (actually a few and some more data structures) 11 p,div{ margin-top:3px; } .error { color:red; }
  • 12. DOM and CSS sitting in a Tree Information from the DOM tree and the Style Structures are used to form the Render Tree. The Render Tree holds the information about what gets painted on the screen. 12
  • 13. CSS Style Matching CSS styles are stored into various maps so that they can be easily retrieved later. 13 div { font-size: 11pt; } table div { font-size: 12pt; } #theId { display: none; } .myClass { color: #ff0000; } Tag ID Class <div> <img src="foo.jpg"> </div> <div> <p>NCDev</p> </div> <p id="theId"></p> <p class="myClass"></p>
  • 14. Quick Advice on CSS Specificity is important, but the rule be as specific as possible is confusing. From a pure performance standpoint • ID Selectors followed by Class Selectors are very fast • Further clarifying these is NOT helpful, its slower p.myClass table#thingy • Descendant Selectors and Child Selectors should be avoided whenever humanly possible .myul_in_a_div {} versus ul div {} 14
  • 15. CSS Caveats Caveats - How specific a selector is determines its weight when styles cascade • It‟s from is a 'style' attribute rather than a rule with a selector • The number of ID attributes in the selector • The number of other attributes and pseudo-classes in the selector • The number of element names and pseudo-elements in the selector 15
  • 16. Understanding the Render Tree The render tree is about the visual aspects of your display 16 div { font-size: 11pt; } img { display: none; }
  • 17. Putting it all together Manipulating the DOM is the slowest thing we can do in the web environment. Depending on what we do, the browser needs to mark things as invalid. The process of making them valid again means executing parts of this diagram. 17
  • 18. Repaint Only If we are careful and just make changes to things like color, visibility or other changes that don‟t require new measurement and layout, we can often just execute this part of the chart: 18
  • 19. Re-layout/Flow If we make any change that requires that causes a size or positioning difference we need to minimally executed these parts of the chart. 19
  • 20. Do Less Work The simple truth behind making DOM interactions faster is to do less of it… A few ways to do less • Execute the smallest amount of that flow chart that you can at any time • Actively worry if your choices make the browser execute any part of it multiple times in a row • Pay attention to how much of the trees your impacting • Do your best to let the browser do this work when it is ready 20
  • 21. Tooling There are many excellent tools you can use to debug and look into the information we are about to discuss. We are just going to use Chrome‟s built in tooling for the moment, but here are some resources: 21  YSlow  Chrome Plugin  Firefox  Speed Tracer  Chrome Plugin  FireBug  Firefox  dynaTrace (5 day trial)  IE Extension  Firefox  jsPerf  Webpagetest.org  (More every 5 minutes)
  • 22. Chrome‟s Tools Chrome has a great set of tools that will get us started and they are all built in Tools • Network View • Timeline • CSS Profiler 22 Render Information • Paint Rectangles • Composited Layer Borders • FPS Meter • Continuous Page Repainting
  • 23. Example 1 – Sized versus Non-Sized Regions/Images Really old statement everyone knows: • Whenever possible, you should provide a width and height for your images Why? 23
  • 24. Example 2 – Visibility versus Display None Performance Statement: • You should/shouldn‟t use visibility/display none when you want to hide something. Why? 24
  • 25. Example 3 – Synchronous Layout Performance Statement: • You need to batch your changes to the DOM. Always try to make a single class change versus multiple changes. Why? 25
  • 26. Example 4 – Off Dom Manipulation Performance Statement: • If you have to make DOM changes, you should make them „off dom‟ Why? 26
  • 27. Do Less Work Sooner The perceived responsiveness of your page/application also depends on how quickly it starts up. This ultimately comes down to a few factors • How much do we need to load on startup? • How quickly can we load it? • How much work must we do when everything arrives? 27
  • 28. Example 6 – CSS Serial Loading Performance Statement: • Using CSS @import can slow down your page load Why? 28
  • 29. Example 7 – CSS Media Queries Performance Statement: • CSS Media Queries are good/bad for performance Why? 29
  • 30. Example 8 – Forced Synchronous Loading Performance Statement: • The order between external CSS and external Scripts in the browser can have major performance implications Why? 30
  • 31. Example 9 – Script Placement Performance Statement: • Your scripts need to be at the top/bottom of your page at all times. Why? 31
  • 32. Selected Resources WebCore Rendering – Parts I through IV https://www.webkit.org/blog/114/webcore-rendering-i-the-basics/ How Browsers Work: Behind the scenes of modern web browsers http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/ Grosskurth, Alan. A Reference Architecture for Web Browsers http://grosskurth.ca/papers/browser-refarch.pdf The new game show: “Will it reflow?” http://www.phpied.com/the-new-game-show-will-it-reflow/ …more to be posted… 32
  • 33. 33 Optimizing Browser DOM Rendering Michael Labriola - @mlabriola Senior Consultant w/ Digital Primates

Hinweis der Redaktion

  1. Image licensed under creative commons attribution license. Found at http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/
  2. To combine these trees, the correct style needs to be computed for each element in the DOM tree. CSS styles are stored into various maps (buckets) so that they can be easily retrieved later. The mappings reduce the scope of the search, using the right most key of the selector.
  3. Image licensed under creative commons attribution license. Found at http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/This all matters for a simple reason. Manipulating the DOM is the slowest thing we can do in the web environment. Depending on what we do, the browser needs to mark things as invalid. The process of making them valid again means executing parts of this diagram.
  4. Image licensed under creative commons attribution license. Found at http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/
  5. Image licensed under creative commons attribution license. Found at http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/