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)

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 

Please Don't Touch the Slow Parts V3