SlideShare a Scribd company logo
1 of 85
Download to read offline
Please Don’t Touch
 the Slow Parts V3
         francesco.fullone@ideato.it
             http://www.ideato.it/

        federico.galassi@cleancode.it
          http://federico.galassi.net/
federico.galassi@cleancode.it
twitter.com/federicogalassi
slideshare.net/fgalassi
fast er
fast er WEB
Faster == Better?
We have to wait
... All the time
“Savings in time
feels like simplicity”
“Time is the only
commodity that matters”
Psychology of web
   performance
                                                                                5-8
                                                                             SECONDS




http://www.websiteoptimization.com/speed/tweak/psychology-web-performance/
Faster web, more clicks




  http://www.stevesouders.com/blog/2009/07/27/wikia-fast-pages-retain-users/
Faster web, better SEO




http://googlewebmastercentral.blogspot.com/2010/04/using-site-speed-in-web-search-ranking.html
Faster web is hot
Say web, Say browser
How browsers work
User clicks on a link
Browser resolves
       domain name                           DNS
                       UDP

            www.google.com




                             72.14.234.104




domain
Browser connects to
    web server                     WEB
                      TCP/IP

                   72.14.234.104




domain   connect
Browser sends a
    request for a page                                WEB
                                   HTTP
                          GET /language_tools?hl=en
                          Host: www.google.com




domain   connect   send
Browser receives a
response with the page                     WEB




                                    HTTP

                                200 OK




domain   connect   send   receive
Browser renders the
    new page



domain   connect   send   receive   render
Rendering is complex
         render
Rendering is
loading resources
                           render

css

      css

            img

                  img

                   javascript

                          javascript

                                flash
Each resource is another
      web request
           render
Requests are
processed in parallel
         render
Rendering is parsing
                                    render

              HTML                                           DOM TREE
<html>                                         - document
  <head>                                         - elem: html
                                                   - elem: head
    <title>Title</title>                           - elem: title
  </head>                                            - text: Title
  <body>                                         - elem: body
    <div>This is a Text</div>                      - elem: div
                                                     - text: This is a Text
    <div id="hidden">Hidden</div>
                                                   - elem: div
                                                     - attr: id=hidden
                                                     - text: Hidden

               CSS                                           STYLE STRUCT
                                             - selector: body
                                               rule:
  body {
                                                 display: block        #   default css
    padding: 0;                                  padding-bottom: 0px   #   site css
  }                                              padding-left: 0px     #   site css
  #hidden {                                      padding-right: 0px    #   site css
      display: none;                             padding-top: 0px      #   site css
                                             - selector: hidden
  }                                            rule:
                                                 display: none         # site css
Rendering is layout
                                               render
                DOM TREE
  - document
    - elem: html
      - elem: head
      - elem: title
        - text: Title
                                            reflow
    - elem: body
      - elem: div                                        RENDER TREE
        - text: This is a Text
      - elem: div
                                                        - root
        - attr: id=hidden
        - text: Hidden
                                                          - body
                                                            - block
               STYLE STRUCT                                    - inline: This is
- selector: body                                               - inline: a Text
  rule:
    display: block        #   default css
    padding-bottom: 0px   #   site css
    padding-left: 0px     #   site css
    padding-right: 0px    #   site css
    padding-top: 0px      #   fsite css
- selector: hidden
  rule:
    display: none         # site css
Rendering is painting
                               render




 RENDER TREE
                           repaint
- root
                                        This is
  - body
    - block
       - inline: This is
                                        a Text
       - inline: a Text
Rendering is execution
           render



        INPUT




                    EVENT QUEUE

                    mouse moved
                    mouse pressed
   OS               mouse released
                    key pressed
                    key released
Execution in one thread
               render


             mouse moved EVENT QUEUE
             mouse pressed
             mouse released
             key pressed
             key released




                                        Native
Javascript
                                       Browser
Execution
                                        Action
Once upon a time...
         Static pages
         Few resources
         Less javascript
Most time on server
domain connect   send   receive   render
Solution is faster serverside
 domain connect   send   receive   render
Ajax revolution
perfo rmance
Ajax revolution
Page updating
     One time
     (classic)   WEB
Page updating
    On demand
      (ajax)         WEB




     ... later ...
Page updating
    Continuous
     (polling)   WEB
Page updating
       Push
     (comet)    WEB
Most time on browser
domain connect   send   receive   render
Golden rule of faster web
 80% of the end user
response time is spent
   on the front-end
Golden rule of faster web
     Start there.
Why web
slow parts?
Easy to understand
Each part has its rules
Which parts are slow?
Network is slow
Less stuff
Fewer requests
         Too many resources



           Concatenate js/css
           Css sprites
           Inline images
Less stuff
Cache requests
          Resources
          re-downloaded

          Expires header
          Revving Files
          External js/css
          Remove etags
Smaller stuff
Compress responses
          Resources are too big



              Content-Encoding
              Gzip
              Deflate
Smaller stuff
Minify responses
         Resources are too big

              js, css, html
              remove formatting
              remove comments
              optimize images
              use tools
Closer stuff
Use a CDN

        Resources are too far

              reduce latency
Closer stuff
Flush document early

            Server can be slow

             Chunked encoding
Browser is slow
Scripts block loading
html
                                        document.write
       javascript
                                        location.href
                       css
                                        scripts order
                       img

                    javascript

                                 img

                                 flash
Put scripts at bottom
 html

        css

        img

              img

              flash

                     javascript

                                  javascript
Unloaded styles
block page rendering
 html

        img

        img

        flash

        css
Put styles at top
html

       css

       img

       img

       flash
Indeed ... scripts block
     everything
Load scripts
        asynchronously
var scriptTag = document.createElement("script")
scriptTag.src = "http://www.example.org/js/lib.js"

document.getElementsByTagName("head")[0]
        .appendChild(scriptTag)
Yield with timers
// doSomethingLong() is too slow, split it

doSomething()

setTimeout(function() {
    doSomethingElse()
}, 50)
Browser I/O
  is slow
D OM
Browser I/O
  is slow
     DoG
D OM
 is alive
 DOM access triggers a live query



         Collections to arrays
         Cache values to variables
D OM
triggers events
         Events execute JS code



             Event Delegation
Reflow is expensive
                                         Batch DOM
                                         changes “offline”




                                     Cloned element
                                     Document Fragment
                                     Display: none

  http://www.youtube.com/watch?v=ZTnIxIA5KGw
Reflow is expensive
                                         Batch CSS
                                         changes




                                  One class to rule em all
                                  Dynamic style property


  http://www.youtube.com/watch?v=ZTnIxIA5KGw
Inefficient element
     location
             CSS are bottom-up!
             #header li a direction



           Be specific on the “right”
Inefficient element
     location
            Go native in DOM




             getElementById
             Xpath
             querySelectorAll
Rules pitfalls
Panta rei
Browserscope



  http://www.browserscope.org/
Expect the unexpected


           empty cache
           no compression
Know your users
Track user capabilities
Conflicting rules
          DNS vs Parallel
          Inline vs External
         Concatenated vs Reuse
All that glitters
  is not gold
Everything is a
   tradeoff
performance brings
    complexity
know the rules but...
leave complexity
  to computers
use libraries
during development
Use tools
at build time



 http://code.google.com/speed/tools.html
Code smart
                   at run time

                                           Adaptive
                                          Optimization


http://www.slideshare.net/ajaxexperience2009/david-wei-and-changhao-jiang-presentation
http://abetterbrowser.org/
Questions?

More Related Content

What's hot

How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
vathur
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 

What's hot (20)

Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
Week 1 (v3)
Week 1 (v3)Week 1 (v3)
Week 1 (v3)
 
Week 1
Week 1Week 1
Week 1
 
Week 1
Week 1Week 1
Week 1
 
Html5 shubelal
Html5 shubelalHtml5 shubelal
Html5 shubelal
 
CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong? CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong?
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5
 
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
CSS pattern libraries
CSS pattern librariesCSS pattern libraries
CSS pattern libraries
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
Html5 public
Html5 publicHtml5 public
Html5 public
 
I Left My JWT in San JOSE
I Left My JWT in San JOSEI Left My JWT in San JOSE
I Left My JWT in San JOSE
 
Offline capable web applications with Google Gears and Dojo Offline
Offline capable web applications with Google Gears and Dojo OfflineOffline capable web applications with Google Gears and Dojo Offline
Offline capable web applications with Google Gears and Dojo Offline
 
Exploring Critical Rendering Path
Exploring Critical Rendering PathExploring Critical Rendering Path
Exploring Critical Rendering Path
 
The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013
 
Introduction to the Emerging JSON-Based Identity and Security Protocols
Introduction to the Emerging JSON-Based Identity and Security ProtocolsIntroduction to the Emerging JSON-Based Identity and Security Protocols
Introduction to the Emerging JSON-Based Identity and Security Protocols
 
Drupal8 migrate
Drupal8 migrateDrupal8 migrate
Drupal8 migrate
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
AMD - Why, What and How
AMD - Why, What and HowAMD - Why, What and How
AMD - Why, What and How
 

Viewers also liked (6)

Canvas
CanvasCanvas
Canvas
 
MongoDB Aug2010 SF Meetup
MongoDB Aug2010 SF MeetupMongoDB Aug2010 SF Meetup
MongoDB Aug2010 SF Meetup
 
Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)
 
A/B Testing Framework Design
A/B Testing Framework DesignA/B Testing Framework Design
A/B Testing Framework Design
 
High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)High Performance HTML5 (SF HTML5 UG)
High Performance HTML5 (SF HTML5 UG)
 
Visual guide to selling software as a service by @prezly
Visual guide to selling software as a service by @prezlyVisual guide to selling software as a service by @prezly
Visual guide to selling software as a service by @prezly
 

Similar to Please Don't Touch the Slow Parts V3

High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
drywallbmb
 
建立前端開發團隊 - 2011 中華電信訓練所版
建立前端開發團隊 - 2011 中華電信訓練所版建立前端開發團隊 - 2011 中華電信訓練所版
建立前端開發團隊 - 2011 中華電信訓練所版
Joseph Chiang
 
Chrome Internals: Paint and Composition
Chrome Internals: Paint and CompositionChrome Internals: Paint and Composition
Chrome Internals: Paint and Composition
Dzmitry Varabei
 

Similar to Please Don't Touch the Slow Parts V3 (20)

Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
 
High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
 
Progressive Downloads and Rendering
Progressive Downloads and RenderingProgressive Downloads and Rendering
Progressive Downloads and Rendering
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Death of a Themer
Death of a ThemerDeath of a Themer
Death of a Themer
 
Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX Designers
 
Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)
 
建立前端開發團隊 - 2011 中華電信訓練所版
建立前端開發團隊 - 2011 中華電信訓練所版建立前端開發團隊 - 2011 中華電信訓練所版
建立前端開發團隊 - 2011 中華電信訓練所版
 
Solving Common Web Component Problems - Simon MacDonald
Solving Common Web Component Problems - Simon MacDonaldSolving Common Web Component Problems - Simon MacDonald
Solving Common Web Component Problems - Simon MacDonald
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
Advanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyAdvanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & Efficiency
 
Diazo: Bridging Designers and Programmers
Diazo: Bridging Designers and ProgrammersDiazo: Bridging Designers and Programmers
Diazo: Bridging Designers and Programmers
 
Building performance auf der Developer Conference Hamburg
Building performance auf der Developer Conference HamburgBuilding performance auf der Developer Conference Hamburg
Building performance auf der Developer Conference Hamburg
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Headless - the future of e-commerce
Headless - the future of e-commerceHeadless - the future of e-commerce
Headless - the future of e-commerce
 
Rails + Sencha = Netzke
Rails + Sencha = NetzkeRails + Sencha = Netzke
Rails + Sencha = Netzke
 
DirectToWeb 2.0
DirectToWeb 2.0DirectToWeb 2.0
DirectToWeb 2.0
 
Chrome Internals: Paint and Composition
Chrome Internals: Paint and CompositionChrome Internals: Paint and Composition
Chrome Internals: Paint and Composition
 
Css
CssCss
Css
 
Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...
 

More from Federico Galassi

More from Federico Galassi (10)

Vim, the Way of the Keyboard
Vim, the Way of the KeyboardVim, the Way of the Keyboard
Vim, the Way of the Keyboard
 
The Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsThe Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous Beasts
 
Javascript the New Parts v2
Javascript the New Parts v2Javascript the New Parts v2
Javascript the New Parts v2
 
CouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental ComplexityCouchApps: Requiem for Accidental Complexity
CouchApps: Requiem for Accidental Complexity
 
Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
 
Event Driven Javascript
Event Driven JavascriptEvent Driven Javascript
Event Driven Javascript
 
Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2Please Don't Touch the Slow Parts V2
Please Don't Touch the Slow Parts V2
 
Please Don't Touch the Slow Parts
Please Don't Touch the Slow PartsPlease Don't Touch the Slow Parts
Please Don't Touch the Slow Parts
 
Javascript The Good Parts v2
Javascript The Good Parts v2Javascript The Good Parts v2
Javascript The Good Parts v2
 
Javascript The Good Parts
Javascript The Good PartsJavascript The Good Parts
Javascript The Good Parts
 

Recently uploaded

Recently uploaded (20)

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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Please Don't Touch the Slow Parts V3