SlideShare a Scribd company logo
Chapter 3:  DOM Scripting Stoyan Stefanov Yahoo! Search Bayjax – April 13, 2010
Tonight: DOM is slow How  slow? Why   is it slow? What  to do about it?
How  slow?
// bad  var  count =  0 ; for  (; count <  15000 ; count += 1) { document . getElementById ( 'here' ). innerHTML  +=  'a' ;  } // DOM access = (1 get + 1 set) * 15000
// better var  count =  0 , content =  '' ;  for  (; count <  15000 ; count += 1) { content +=  'a' ;  } document . getElementById ( 'here' ). innerHTML  += content; // DOM access: get + set
How  bad are we talking about?
Why  slow?
The bridge DOM land ECMA land
The browser
Dynatrace
Dynatrace
Speed tracer
bodystyle.color = 'red'; tmp = computed.backgroundColor; bodystyle.color = 'white'; tmp = computed.backgroundImage; bodystyle.color = 'green'; tmp = computed.backgroundAttachment; bodystyle.color = 'red'; bodystyle.color = 'white'; bodystyle.color = 'green'; tmp = computed.backgroundColor; tmp = computed.backgroundImage; tmp = computed.backgroundAttachment;
What  to do about it?
10 commandments Don’t touch the DOM Cache DOM references in local  var s Use selectors API Cache the  length  when looping collections Update the DOM offline Batch style changes Don’t ask for layout info excessively Minimize reflow areas Use event delegation (see  Y.delegate() ) Don’t touch the DOM
Etcetera Blog: www.phpied.com Email: [email_address] Twitter: @stoyanstefanov YSlow 2.0

More Related Content

PDF
Webuquerque Web Hosting
PPTX
Javantura v3 - Just say it – using language to communicate with the computer ...
ODP
smusher has_a_location acts_as_feed
PPTX
(WHAT) To Do or Not To Do: Staying Up To Date with PHP Versions
PPTX
Nvvp streams-3
PPT
Tree Top
PDF
ClojureScript Introduction
PDF
Performance patterns
Webuquerque Web Hosting
Javantura v3 - Just say it – using language to communicate with the computer ...
smusher has_a_location acts_as_feed
(WHAT) To Do or Not To Do: Staying Up To Date with PHP Versions
Nvvp streams-3
Tree Top
ClojureScript Introduction
Performance patterns

Similar to High-performance DOM scripting (20)

PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
PPTX
JavaScript front end performance optimizations
PPT
Web performance essentials - Goodies
PDF
Developing High Performance Web Apps
PDF
Shifting Gears
PPTX
How to Make AJAX Applications Scream on the Client
PPTX
the next web now
PPT
High Performance Ajax Applications 1197671494632682 2
PPT
High Performance Ajax Applications
PPT
Web Performance Tips
PPTX
JavaScript performance patterns
PPTX
Building High Performance Web Applications and Sites
PPTX
JavaScript Performance Patterns
PPT
Ajax Performance
PPTX
Building High Perf Web Apps - IE8 Firestarter
PPT
High Performance Web Pages - 20 new best practices
PDF
Front-end optimisation & jQuery Internals (Pycon)
KEY
#NewMeetup Performance
PDF
Performance Optimization and JavaScript Best Practices
PPT
Enhance Web Performance
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
JavaScript front end performance optimizations
Web performance essentials - Goodies
Developing High Performance Web Apps
Shifting Gears
How to Make AJAX Applications Scream on the Client
the next web now
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications
Web Performance Tips
JavaScript performance patterns
Building High Performance Web Applications and Sites
JavaScript Performance Patterns
Ajax Performance
Building High Perf Web Apps - IE8 Firestarter
High Performance Web Pages - 20 new best practices
Front-end optimisation & jQuery Internals (Pycon)
#NewMeetup Performance
Performance Optimization and JavaScript Best Practices
Enhance Web Performance
Ad

More from Stoyan Stefanov (20)

PDF
Reactive JavaScript
PPTX
YSlow hacking
PPTX
Liking performance
PPTX
High Performance Social Plugins
PDF
Social Button BFFs
PPTX
JavaScript навсякъде
PPTX
JavaScript is everywhere
PDF
JavaScript shell scripting
PDF
JavaScript for PHP developers
PDF
WPO @ PubCon 2010
PDF
Progressive Downloads and Rendering - take #2
PDF
Progressive Downloads and Rendering
PDF
Voices that matter: High Performance Web Sites
PDF
Psychology of performance
PPT
3-in-1 YSlow
PDF
CSS and image optimization
PPT
The business of performance
PDF
JavaScript Patterns
PDF
Ignite Velocity: Image Weight Loss Clinic
PDF
Don't make me wait! or Building High-Performance Web Applications
Reactive JavaScript
YSlow hacking
Liking performance
High Performance Social Plugins
Social Button BFFs
JavaScript навсякъде
JavaScript is everywhere
JavaScript shell scripting
JavaScript for PHP developers
WPO @ PubCon 2010
Progressive Downloads and Rendering - take #2
Progressive Downloads and Rendering
Voices that matter: High Performance Web Sites
Psychology of performance
3-in-1 YSlow
CSS and image optimization
The business of performance
JavaScript Patterns
Ignite Velocity: Image Weight Loss Clinic
Don't make me wait! or Building High-Performance Web Applications
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
Teaching material agriculture food technology
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
1. Introduction to Computer Programming.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
1. Introduction to Computer Programming.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25-Week II
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction

High-performance DOM scripting

  • 1. Chapter 3: DOM Scripting Stoyan Stefanov Yahoo! Search Bayjax – April 13, 2010
  • 2. Tonight: DOM is slow How slow? Why is it slow? What to do about it?
  • 4. // bad var count = 0 ; for (; count < 15000 ; count += 1) { document . getElementById ( 'here' ). innerHTML += 'a' ; } // DOM access = (1 get + 1 set) * 15000
  • 5. // better var count = 0 , content = '' ; for (; count < 15000 ; count += 1) { content += 'a' ; } document . getElementById ( 'here' ). innerHTML += content; // DOM access: get + set
  • 6. How bad are we talking about?
  • 8. The bridge DOM land ECMA land
  • 13. bodystyle.color = 'red'; tmp = computed.backgroundColor; bodystyle.color = 'white'; tmp = computed.backgroundImage; bodystyle.color = 'green'; tmp = computed.backgroundAttachment; bodystyle.color = 'red'; bodystyle.color = 'white'; bodystyle.color = 'green'; tmp = computed.backgroundColor; tmp = computed.backgroundImage; tmp = computed.backgroundAttachment;
  • 14. What to do about it?
  • 15. 10 commandments Don’t touch the DOM Cache DOM references in local var s Use selectors API Cache the length when looping collections Update the DOM offline Batch style changes Don’t ask for layout info excessively Minimize reflow areas Use event delegation (see Y.delegate() ) Don’t touch the DOM
  • 16. Etcetera Blog: www.phpied.com Email: [email_address] Twitter: @stoyanstefanov YSlow 2.0