SlideShare una empresa de Scribd logo
1 de 85
Descargar para leer sin conexión
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?

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado (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 a 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 a 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...
 

Más de Federico Galassi

Más de 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
 

Último

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
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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...
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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?
 
[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
 
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
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Please Don't Touch the Slow Parts V3