SlideShare una empresa de Scribd logo
1 de 79
Descargar para leer sin conexión
Improve your
                              Javascript
                             Performance




                                   Devon2011 DAUM
Wednesday, November 23, 11
About Me
                    Web Programmer          2002 ~ 2009
                    Frontend Programmer 2009 ~
                    FT Projects
                        Cafe
                        Tistory T-Edition
                        Daum Editor
                        Frontend Research / Support

Wednesday, November 23, 11
Wednesday, November 23, 11
Why Slow



Wednesday, November 23, 11
Javascript is an
               “interpreted” language


Wednesday, November 23, 11
‘No’ Compiler
                              Optimization


Wednesday, November 23, 11
But, JIT Compilers
                     in Modern Browser


Wednesday, November 23, 11
JS Engine Benchmarks

             IE9

    Chrome13

    Opera11.5

       Firefox7

       Safari5.1

                   0ms            750ms              1500ms            2250ms               3000ms
                                     SunSpider Score in ms (lower is better)

                     http://www.pcmag.com/article2/0,2817,2349496,00.asp#fbid=ce57IR_ZxrY

Wednesday, November 23, 11
JS Engine Benchmarks
                                                                                               IE7


             IE9

    Chrome13

    Opera11.5

       Firefox7

       Safari5.1

                   0ms            750ms              1500ms            2250ms               3000ms
                                     SunSpider Score in ms (lower is better)

                     http://www.pcmag.com/article2/0,2817,2349496,00.asp#fbid=ce57IR_ZxrY

Wednesday, November 23, 11
Wednesday, November 23, 11
Life of Javascript
                    Connect
                    Download
                    Parse
                    Execute
                    DOM Interaction
                    UI Updates


Wednesday, November 23, 11
JS Engine cares only...
                    Connect      Network Latency
                    Download     Blocking Browser
                    Parse
                    Execute
                    DOM Interaction     DOM Interaction Cost
                    UI Updates     Rendering Issue


Wednesday, November 23, 11
IE
 Empire




                                                   HTML5




Wednesday, November 23, 11
Usage Share of Web Browsers




     2010/10                         2011/4                     2011/9              2011/10



                IE8          IE6       IE7        IE9        Chrome      Safari   Firefox

                                          2011/10/03 www.daum.net 기준


Wednesday, November 23, 11
Wednesday, November 23, 11
Old Browsers Usage Share

                    Mobile Environment

                    Other Bottlenecks




Wednesday, November 23, 11
Code Tuning Technique



Wednesday, November 23, 11
Scope Chains




Wednesday, November 23, 11
function initUI() {
              var body = document.body,
                  links = document.getElementsByTagName(a),
                  i = 0,
                  len = links.length;

                       while (i  len) {
                           update(links[i++]);
                       }

                       document.getElementById(go-btn).onclick = function() {
                           start();
                       }

                       bd.className = active;
          }




Wednesday, November 23, 11
function initUI() {
              var doc = document,
                  body = doc.body,
                  links = doc.getElementsByTagName(a),
                  i = 0,
                  len = links.length;

                       while (i  len) {
                           update(links[i++]);
                       }

                       doc.getElementById(go-btn).onclick = function() {
                           start();
                       }

                       bd.className = active;
          }




Wednesday, November 23, 11
function initUI() {
              var doc = document,
                  body = doc.body,
                  links = doc.getElementsByTagName(a),
                  i = 0,
                  len = links.length;

                       while (i  len) {
                           update(links[i++]);
                       }

                       doc.getElementById(go-btn).onclick = function() {
                           start();
                       }

                       bd.className = active;
          }




Wednesday, November 23, 11
Nested Members



Wednesday, November 23, 11
function toggle(element) {
                    if (daum.util.dom.hasClass(element, selected)) {
                        daum.util.dom.removeClass(element, selected);
                    } else {
                        daum.util.dom.addClass(element, selected);
                    }
                }




Wednesday, November 23, 11
function toggle(element) {
                    var domutil = daum.util.dom;
                    if (domutil.hasClass(element, selected)) {
                        domutil.removeClass(element, selected);
                    } else {
                        domutil.addClass(element, selected);
                    }
                }




Wednesday, November 23, 11
L∞p



Wednesday, November 23, 11
for (var i = 0; i  items.length; i++) {
                    process(items[i]);
                }




Wednesday, November 23, 11
var k = items.length - 1;
                             do {
                                  process(items[k]);
                             } while (k--);




Wednesday, November 23, 11
Wednesday, November 23, 11
Scope Chain

                    Nested Member

                    Loop




Wednesday, November 23, 11
Scope Chain

                    Nested Member

                    Loop




Wednesday, November 23, 11
Scope Chain


                             FA IL
                    Nested Member

                    Loop




Wednesday, November 23, 11
Real World Bottleneck




Wednesday, November 23, 11
Wednesday, November 23, 11
DOM

                  Reflow

                  UI Thread



Wednesday, November 23, 11
Daum Top DOM visualization - http://www.aharef.info/static/htmlgraph/

Wednesday, November 23, 11
DOM




     Daum Top DOM visualization - http://www.aharef.info/static/htmlgraph/

Wednesday, November 23, 11
‘The Document Object Model (DOM) is an
                 application programming interface (API) for
                         HTML and XML documents’




Wednesday, November 23, 11
‘The Document Object Model (DOM) is an
                 application programming interface (API) for
                         HTML and XML documents’




Wednesday, November 23, 11
DOM is not part of
                      javascript engine
                         Javascript Engine         DOM Engine

                         JScript (jscript.dll)   Trident (mshtml.dll)

                                Nitro                WebCore

                                 V8                  WebCore

                             TraceMonkey               Gecko



Wednesday, November 23, 11
‘Give
 me
 your
 money’




Wednesday, November 23, 11
DOM is Expensive
              Minimize DOM Access
              Avoid HTMLCollection


Wednesday, November 23, 11
Wednesday, November 23, 11
Wednesday, November 23, 11
Reflow



Wednesday, November 23, 11
UI Updates = Reflow + Repaint




Wednesday, November 23, 11
Parsing HTML to
                             Render tree    Layout of the   Painting the
    construct the
                             construction    render tree    render tree
      DOM tree




Wednesday, November 23, 11
Parsing HTML to
                             Render tree    Layout of the   Painting the
    construct the
                             construction    render tree    render tree
      DOM tree




Wednesday, November 23, 11
Parsing HTML to
                             Render tree    Layout of the   Painting the
    construct the
                             construction    render tree    render tree
      DOM tree




                                                             { width, height, x, y }

                                                             { width, height, x, y }


                                                             { width, height, x, y }

                                                             { width, height, x, y }


                                                                    { width, height, x, y }


                                                                    { width, height, x, y }




Wednesday, November 23, 11
Parsing HTML to
                             Render tree    Layout of the   Painting the
    construct the
                             construction    render tree    render tree
      DOM tree




Wednesday, November 23, 11
Wednesday, November 23, 11
Causing Reflow
                    Page renders initially
                    Window is resized
                    Visible DOM elements are added or removed
                    Element change position
                    Element change size
                        margin, padding, border, width, height

                    text changes, image replaced with different size


Wednesday, November 23, 11
Reflow is Expensive
               Batch Style Changes
              Use Flow-Off Technique
              Avoid Geometry Access

Wednesday, November 23, 11
Wednesday, November 23, 11
Wednesday, November 23, 11
UI Thread



Wednesday, November 23, 11
UI Thread


                    Draw UI Updates
                    Execute Javascript




Wednesday, November 23, 11
Wednesday, November 23, 11
Only one job can happen at a time




Wednesday, November 23, 11
Jobs for UI Updates and Javascript Execution
                             are added to a UI Queue
Wednesday, November 23, 11
button.addEventListener(click, function handleClick() {
           doHeavyJob();
           resultDIV.innerHTML = Finish!;
       });




Wednesday, November 23, 11
UI Thread




  UI Queue
    User clicks


     UI Update
      Button


      Javascript
    handleClick()




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update
                              Button




  UI Queue
    User clicks


     UI Update            Javascript
      Button            handleClick()


      Javascript
    handleClick()




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update     Javascript
                              Button     handleClick()




  UI Queue
    User clicks


     UI Update            Javascript
      Button            handleClick()


      Javascript
    handleClick()




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update     Javascript
                              Button     handleClick()




  UI Queue
    User clicks


     UI Update            Javascript
      Button            handleClick()


      Javascript
    handleClick()




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update     Javascript
                              Button     handleClick()




  UI Queue
    User clicks                                    User clicks


     UI Update            Javascript                UI Update
      Button            handleClick()                Button


      Javascript                                    Javascript
    handleClick()                                  otherLogic()




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update     Javascript
                              Button     handleClick()




  UI Queue
    User clicks                          User clicks     User clicks


     UI Update            Javascript      UI Update       UI Update
      Button            handleClick()      Button
                                                          Javascript
      Javascript                           Javascript
    handleClick()                        handleClick()
                                                          UI Update


                                                          Javascript




  Time


Wednesday, November 23, 11
UI Thread

                             UI Update               Javascript
                              Button               handleClick()


                                                                                User clicks
                                                                                User clicks
  UI Queue                                                                      User clicks
    User clicks                          User clicks          User clicks       User clicks


     UI Update            Javascript      UI Update            UI Update         UI Update
      Button            handleClick()      Button
                                                                   Javascript    Javascript
      Javascript                           Javascript
    handleClick()                        handleClick()
                                                               UI Update         UI Update


                                                                   Javascript




  Time


Wednesday, November 23, 11
Wednesday, November 23, 11
“Javascript that executes in
          whole seconds is probably
           doing something wrong...”
         - Brendan Eich, Creator of Javascript




                                          One Second




Wednesday, November 23, 11
How Long Is Too Long?

                 “0.1 second is about the limit for having the
                 user feel that the system is reacting
                 instantaneously, meaning that no special
                 feedback is necessary except to display the
                 result.”
                                           - Jakob Nielsen, 1968



Wednesday, November 23, 11
Yield control to
                                UI Update


Wednesday, November 23, 11
Yielding with Timers




Wednesday, November 23, 11
Wednesday, November 23, 11
Wednesday, November 23, 11
Conclusion




Wednesday, November 23, 11

Más contenido relacionado

La actualidad más candente

Batou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentBatou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentChristian Theune
 
Security and performance designs for client-server communications
Security and performance designs for client-server communicationsSecurity and performance designs for client-server communications
Security and performance designs for client-server communicationsWO Community
 
Performance from the user's perspective
Performance from the user's perspectivePerformance from the user's perspective
Performance from the user's perspectiveorangecoding
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetTom Croucher
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCar
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCarDo Zero ao Node.js - Especialização em Engenharia de Software - UFSCar
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCarPablo Souza
 

La actualidad más candente (9)

Batou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentBatou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deployment
 
Developing Async Sense
Developing Async SenseDeveloping Async Sense
Developing Async Sense
 
Security and performance designs for client-server communications
Security and performance designs for client-server communicationsSecurity and performance designs for client-server communications
Security and performance designs for client-server communications
 
Jongo mongo sv
Jongo mongo svJongo mongo sv
Jongo mongo sv
 
Performance from the user's perspective
Performance from the user's perspectivePerformance from the user's perspective
Performance from the user's perspective
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yet
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCar
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCarDo Zero ao Node.js - Especialização em Engenharia de Software - UFSCar
Do Zero ao Node.js - Especialização em Engenharia de Software - UFSCar
 

Similar a Improve Javascript Performance by Reducing DOM Access and Reflow

Getting started with ClojureScript
Getting started with ClojureScriptGetting started with ClojureScript
Getting started with ClojureScriptSiva Jagadeesan
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...JAX London
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)Sebastian Cohnen
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)benwaine
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Matt Aimonetti
 
Ext JS 4: Advanced Expert Techniques
Ext JS 4: Advanced Expert TechniquesExt JS 4: Advanced Expert Techniques
Ext JS 4: Advanced Expert TechniquesSencha
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentationmskmoorthy
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosBruno Oliveira
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3Blazing Cloud
 
Scala in hulu's data platform
Scala in hulu's data platformScala in hulu's data platform
Scala in hulu's data platformPrasan Samtani
 
Continuous Delivery at Netflix
Continuous Delivery at NetflixContinuous Delivery at Netflix
Continuous Delivery at NetflixRob Spieldenner
 
Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrencyMichael Barker
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornSimon Bagreev
 
Continuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformContinuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformJarrod Overson
 

Similar a Improve Javascript Performance by Reducing DOM Access and Reflow (20)

JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
Getting started with ClojureScript
Getting started with ClojureScriptGetting started with ClojureScript
Getting started with ClojureScript
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)
 
Reintroducing AlloyUI
Reintroducing AlloyUIReintroducing AlloyUI
Reintroducing AlloyUI
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
Ext JS 4: Advanced Expert Techniques
Ext JS 4: Advanced Expert TechniquesExt JS 4: Advanced Expert Techniques
Ext JS 4: Advanced Expert Techniques
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
 
25 Debugging
25 Debugging25 Debugging
25 Debugging
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3
 
Scala in hulu's data platform
Scala in hulu's data platformScala in hulu's data platform
Scala in hulu's data platform
 
Continuous Delivery at Netflix
Continuous Delivery at NetflixContinuous Delivery at Netflix
Continuous Delivery at Netflix
 
Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrency
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and Unicorn
 
Moose
MooseMoose
Moose
 
Continuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformContinuous Delivery for the Web Platform
Continuous Delivery for the Web Platform
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 

Más de Daum DNA

Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)
Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)
Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)Daum DNA
 
Daum OAuth 2.0
Daum OAuth 2.0Daum OAuth 2.0
Daum OAuth 2.0Daum DNA
 
Daum 음성인식 API (김한샘)
Daum 음성인식 API (김한샘)Daum 음성인식 API (김한샘)
Daum 음성인식 API (김한샘)Daum DNA
 
Daum 검색/지도 API (이정주)
Daum 검색/지도 API (이정주)Daum 검색/지도 API (이정주)
Daum 검색/지도 API (이정주)Daum DNA
 
오픈 API 활용방법(Daum 사례 중심, 윤석찬)
오픈 API 활용방법(Daum 사례 중심, 윤석찬)오픈 API 활용방법(Daum 사례 중심, 윤석찬)
오픈 API 활용방법(Daum 사례 중심, 윤석찬)Daum DNA
 
Daum 티스토리 API (천정환)
Daum 티스토리 API (천정환)Daum 티스토리 API (천정환)
Daum 티스토리 API (천정환)Daum DNA
 
Daum 로그인 API (함태윤)
Daum 로그인 API (함태윤)Daum 로그인 API (함태윤)
Daum 로그인 API (함태윤)Daum DNA
 
FT직군의 현재와 미래 - 홍윤표
FT직군의 현재와 미래 - 홍윤표FT직군의 현재와 미래 - 홍윤표
FT직군의 현재와 미래 - 홍윤표Daum DNA
 
웹접근성과 장애인 차별 금지법 - 장성민
웹접근성과 장애인 차별 금지법 - 장성민웹접근성과 장애인 차별 금지법 - 장성민
웹접근성과 장애인 차별 금지법 - 장성민Daum DNA
 
반응형 웹 디자인은 만능인가? - 신현석
반응형 웹 디자인은 만능인가? - 신현석반응형 웹 디자인은 만능인가? - 신현석
반응형 웹 디자인은 만능인가? - 신현석Daum DNA
 
Daum devday 13 [bap]
Daum devday 13  [bap]Daum devday 13  [bap]
Daum devday 13 [bap]Daum DNA
 
Daum DevDay 13-힐링이 필요해
Daum DevDay 13-힐링이 필요해Daum DevDay 13-힐링이 필요해
Daum DevDay 13-힐링이 필요해Daum DNA
 
Daum DevDay 13 - 마음의 소리
Daum DevDay 13 - 마음의 소리Daum DevDay 13 - 마음의 소리
Daum DevDay 13 - 마음의 소리Daum DNA
 
Daum DevDay 13 - OpenBrace
Daum DevDay 13 - OpenBraceDaum DevDay 13 - OpenBrace
Daum DevDay 13 - OpenBraceDaum DNA
 
Daum DevDay 13 - Ogangjang
Daum DevDay 13 - OgangjangDaum DevDay 13 - Ogangjang
Daum DevDay 13 - OgangjangDaum DNA
 
Daum DevDay 13 - Mook
Daum DevDay 13 - MookDaum DevDay 13 - Mook
Daum DevDay 13 - MookDaum DNA
 
Daum DevDay 13 - Moonlight
Daum DevDay 13 - MoonlightDaum DevDay 13 - Moonlight
Daum DevDay 13 - MoonlightDaum DNA
 
Daum DevDay 13 - In-N-Out
Daum DevDay 13 - In-N-OutDaum DevDay 13 - In-N-Out
Daum DevDay 13 - In-N-OutDaum DNA
 
Daum DevDay 13 - i-DF
Daum DevDay 13 - i-DFDaum DevDay 13 - i-DF
Daum DevDay 13 - i-DFDaum DNA
 
Daum 키노트 | Devon 2012
Daum 키노트 | Devon 2012Daum 키노트 | Devon 2012
Daum 키노트 | Devon 2012Daum DNA
 

Más de Daum DNA (20)

Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)
Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)
Daum의 개방형 기술 전략 및 자바 기술 로드맵(2007)
 
Daum OAuth 2.0
Daum OAuth 2.0Daum OAuth 2.0
Daum OAuth 2.0
 
Daum 음성인식 API (김한샘)
Daum 음성인식 API (김한샘)Daum 음성인식 API (김한샘)
Daum 음성인식 API (김한샘)
 
Daum 검색/지도 API (이정주)
Daum 검색/지도 API (이정주)Daum 검색/지도 API (이정주)
Daum 검색/지도 API (이정주)
 
오픈 API 활용방법(Daum 사례 중심, 윤석찬)
오픈 API 활용방법(Daum 사례 중심, 윤석찬)오픈 API 활용방법(Daum 사례 중심, 윤석찬)
오픈 API 활용방법(Daum 사례 중심, 윤석찬)
 
Daum 티스토리 API (천정환)
Daum 티스토리 API (천정환)Daum 티스토리 API (천정환)
Daum 티스토리 API (천정환)
 
Daum 로그인 API (함태윤)
Daum 로그인 API (함태윤)Daum 로그인 API (함태윤)
Daum 로그인 API (함태윤)
 
FT직군의 현재와 미래 - 홍윤표
FT직군의 현재와 미래 - 홍윤표FT직군의 현재와 미래 - 홍윤표
FT직군의 현재와 미래 - 홍윤표
 
웹접근성과 장애인 차별 금지법 - 장성민
웹접근성과 장애인 차별 금지법 - 장성민웹접근성과 장애인 차별 금지법 - 장성민
웹접근성과 장애인 차별 금지법 - 장성민
 
반응형 웹 디자인은 만능인가? - 신현석
반응형 웹 디자인은 만능인가? - 신현석반응형 웹 디자인은 만능인가? - 신현석
반응형 웹 디자인은 만능인가? - 신현석
 
Daum devday 13 [bap]
Daum devday 13  [bap]Daum devday 13  [bap]
Daum devday 13 [bap]
 
Daum DevDay 13-힐링이 필요해
Daum DevDay 13-힐링이 필요해Daum DevDay 13-힐링이 필요해
Daum DevDay 13-힐링이 필요해
 
Daum DevDay 13 - 마음의 소리
Daum DevDay 13 - 마음의 소리Daum DevDay 13 - 마음의 소리
Daum DevDay 13 - 마음의 소리
 
Daum DevDay 13 - OpenBrace
Daum DevDay 13 - OpenBraceDaum DevDay 13 - OpenBrace
Daum DevDay 13 - OpenBrace
 
Daum DevDay 13 - Ogangjang
Daum DevDay 13 - OgangjangDaum DevDay 13 - Ogangjang
Daum DevDay 13 - Ogangjang
 
Daum DevDay 13 - Mook
Daum DevDay 13 - MookDaum DevDay 13 - Mook
Daum DevDay 13 - Mook
 
Daum DevDay 13 - Moonlight
Daum DevDay 13 - MoonlightDaum DevDay 13 - Moonlight
Daum DevDay 13 - Moonlight
 
Daum DevDay 13 - In-N-Out
Daum DevDay 13 - In-N-OutDaum DevDay 13 - In-N-Out
Daum DevDay 13 - In-N-Out
 
Daum DevDay 13 - i-DF
Daum DevDay 13 - i-DFDaum DevDay 13 - i-DF
Daum DevDay 13 - i-DF
 
Daum 키노트 | Devon 2012
Daum 키노트 | Devon 2012Daum 키노트 | Devon 2012
Daum 키노트 | Devon 2012
 

Último

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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 MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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 WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
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 AutomationSafe Software
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Último (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Improve Javascript Performance by Reducing DOM Access and Reflow

  • 1. Improve your Javascript Performance Devon2011 DAUM Wednesday, November 23, 11
  • 2. About Me Web Programmer 2002 ~ 2009 Frontend Programmer 2009 ~ FT Projects Cafe Tistory T-Edition Daum Editor Frontend Research / Support Wednesday, November 23, 11
  • 5. Javascript is an “interpreted” language Wednesday, November 23, 11
  • 6. ‘No’ Compiler Optimization Wednesday, November 23, 11
  • 7. But, JIT Compilers in Modern Browser Wednesday, November 23, 11
  • 8. JS Engine Benchmarks IE9 Chrome13 Opera11.5 Firefox7 Safari5.1 0ms 750ms 1500ms 2250ms 3000ms SunSpider Score in ms (lower is better) http://www.pcmag.com/article2/0,2817,2349496,00.asp#fbid=ce57IR_ZxrY Wednesday, November 23, 11
  • 9. JS Engine Benchmarks IE7 IE9 Chrome13 Opera11.5 Firefox7 Safari5.1 0ms 750ms 1500ms 2250ms 3000ms SunSpider Score in ms (lower is better) http://www.pcmag.com/article2/0,2817,2349496,00.asp#fbid=ce57IR_ZxrY Wednesday, November 23, 11
  • 11. Life of Javascript Connect Download Parse Execute DOM Interaction UI Updates Wednesday, November 23, 11
  • 12. JS Engine cares only... Connect Network Latency Download Blocking Browser Parse Execute DOM Interaction DOM Interaction Cost UI Updates Rendering Issue Wednesday, November 23, 11
  • 13. IE
  • 14.  Empire HTML5 Wednesday, November 23, 11
  • 15. Usage Share of Web Browsers 2010/10 2011/4 2011/9 2011/10 IE8 IE6 IE7 IE9 Chrome Safari Firefox 2011/10/03 www.daum.net 기준 Wednesday, November 23, 11
  • 17. Old Browsers Usage Share Mobile Environment Other Bottlenecks Wednesday, November 23, 11
  • 20. function initUI() { var body = document.body, links = document.getElementsByTagName(a), i = 0, len = links.length; while (i len) { update(links[i++]); } document.getElementById(go-btn).onclick = function() { start(); } bd.className = active; } Wednesday, November 23, 11
  • 21. function initUI() { var doc = document, body = doc.body, links = doc.getElementsByTagName(a), i = 0, len = links.length; while (i len) { update(links[i++]); } doc.getElementById(go-btn).onclick = function() { start(); } bd.className = active; } Wednesday, November 23, 11
  • 22. function initUI() { var doc = document, body = doc.body, links = doc.getElementsByTagName(a), i = 0, len = links.length; while (i len) { update(links[i++]); } doc.getElementById(go-btn).onclick = function() { start(); } bd.className = active; } Wednesday, November 23, 11
  • 24. function toggle(element) { if (daum.util.dom.hasClass(element, selected)) { daum.util.dom.removeClass(element, selected); } else { daum.util.dom.addClass(element, selected); } } Wednesday, November 23, 11
  • 25. function toggle(element) { var domutil = daum.util.dom; if (domutil.hasClass(element, selected)) { domutil.removeClass(element, selected); } else { domutil.addClass(element, selected); } } Wednesday, November 23, 11
  • 27. for (var i = 0; i items.length; i++) { process(items[i]); } Wednesday, November 23, 11
  • 28. var k = items.length - 1; do { process(items[k]); } while (k--); Wednesday, November 23, 11
  • 30. Scope Chain Nested Member Loop Wednesday, November 23, 11
  • 31. Scope Chain Nested Member Loop Wednesday, November 23, 11
  • 32. Scope Chain FA IL Nested Member Loop Wednesday, November 23, 11
  • 35. DOM Reflow UI Thread Wednesday, November 23, 11
  • 36. Daum Top DOM visualization - http://www.aharef.info/static/htmlgraph/ Wednesday, November 23, 11
  • 37. DOM Daum Top DOM visualization - http://www.aharef.info/static/htmlgraph/ Wednesday, November 23, 11
  • 38. ‘The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents’ Wednesday, November 23, 11
  • 39. ‘The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents’ Wednesday, November 23, 11
  • 40. DOM is not part of javascript engine Javascript Engine DOM Engine JScript (jscript.dll) Trident (mshtml.dll) Nitro WebCore V8 WebCore TraceMonkey Gecko Wednesday, November 23, 11
  • 42.  me
  • 45. DOM is Expensive Minimize DOM Access Avoid HTMLCollection Wednesday, November 23, 11
  • 49. UI Updates = Reflow + Repaint Wednesday, November 23, 11
  • 50. Parsing HTML to Render tree Layout of the Painting the construct the construction render tree render tree DOM tree Wednesday, November 23, 11
  • 51. Parsing HTML to Render tree Layout of the Painting the construct the construction render tree render tree DOM tree Wednesday, November 23, 11
  • 52. Parsing HTML to Render tree Layout of the Painting the construct the construction render tree render tree DOM tree { width, height, x, y } { width, height, x, y } { width, height, x, y } { width, height, x, y } { width, height, x, y } { width, height, x, y } Wednesday, November 23, 11
  • 53. Parsing HTML to Render tree Layout of the Painting the construct the construction render tree render tree DOM tree Wednesday, November 23, 11
  • 55. Causing Reflow Page renders initially Window is resized Visible DOM elements are added or removed Element change position Element change size margin, padding, border, width, height text changes, image replaced with different size Wednesday, November 23, 11
  • 56. Reflow is Expensive Batch Style Changes Use Flow-Off Technique Avoid Geometry Access Wednesday, November 23, 11
  • 60. UI Thread Draw UI Updates Execute Javascript Wednesday, November 23, 11
  • 62. Only one job can happen at a time Wednesday, November 23, 11
  • 63. Jobs for UI Updates and Javascript Execution are added to a UI Queue Wednesday, November 23, 11
  • 64. button.addEventListener(click, function handleClick() { doHeavyJob(); resultDIV.innerHTML = Finish!; }); Wednesday, November 23, 11
  • 65. UI Thread UI Queue User clicks UI Update Button Javascript handleClick() Time Wednesday, November 23, 11
  • 66. UI Thread UI Update Button UI Queue User clicks UI Update Javascript Button handleClick() Javascript handleClick() Time Wednesday, November 23, 11
  • 67. UI Thread UI Update Javascript Button handleClick() UI Queue User clicks UI Update Javascript Button handleClick() Javascript handleClick() Time Wednesday, November 23, 11
  • 68. UI Thread UI Update Javascript Button handleClick() UI Queue User clicks UI Update Javascript Button handleClick() Javascript handleClick() Time Wednesday, November 23, 11
  • 69. UI Thread UI Update Javascript Button handleClick() UI Queue User clicks User clicks UI Update Javascript UI Update Button handleClick() Button Javascript Javascript handleClick() otherLogic() Time Wednesday, November 23, 11
  • 70. UI Thread UI Update Javascript Button handleClick() UI Queue User clicks User clicks User clicks UI Update Javascript UI Update UI Update Button handleClick() Button Javascript Javascript Javascript handleClick() handleClick() UI Update Javascript Time Wednesday, November 23, 11
  • 71. UI Thread UI Update Javascript Button handleClick() User clicks User clicks UI Queue User clicks User clicks User clicks User clicks User clicks UI Update Javascript UI Update UI Update UI Update Button handleClick() Button Javascript Javascript Javascript Javascript handleClick() handleClick() UI Update UI Update Javascript Time Wednesday, November 23, 11
  • 73. “Javascript that executes in whole seconds is probably doing something wrong...” - Brendan Eich, Creator of Javascript One Second Wednesday, November 23, 11
  • 74. How Long Is Too Long? “0.1 second is about the limit for having the user feel that the system is reacting instantaneously, meaning that no special feedback is necessary except to display the result.” - Jakob Nielsen, 1968 Wednesday, November 23, 11
  • 75. Yield control to UI Update Wednesday, November 23, 11
  • 80. 1. Digg the low level JS Perf. characteristics But, premature optimization is evil Wednesday, November 23, 11
  • 81. 2. Don’t touch the SLOW PART! DOM Reflow UI Thread Wednesday, November 23, 11
  • 82. Make the Web Faster Make the Web Responsive Wednesday, November 23, 11