SlideShare a Scribd company logo
1 of 155
Download to read offline
High Performance JavaScript Nicholas C. Zakas| nczonline.net
Who's this guy? Co-Creator csslint.net Contributor, Creator of YUI Test Ex-tech lead Yahoo! Author Lead Author Contributor Lead Author
@slicknet (complaints: @brendaneich)
Does JavaScript performance matter?
All browsers now haveoptimizing JavaScript engines Tracemonkey/ JaegarMonkey (3.5+) V8 (all) Nitro (4+) Chakra (9+) Karakan (10.5+)
http://ie.microsoft.com/testdrive/benchmarks/sunspider/default.html
Old computers ran slow applications Small amounts of CPU power and memory
New computers are generally faster but slow applications still exist More CPU + more memory = less disciplined application development
Oh yeah, one more thing
It's still possible to write slow JavaScript
JavaScript performancedirectlyaffects user experience
The UI Threadaka Browser Event Loop
The browser UI thread is responsible for both UI updates and JavaScript execution Only one can happen at a time
Jobs for UI updates and JavaScript execution are added to a UI queue Each job must wait in line for its turn to execute
<button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){    document.getElementById("btn").onclick = function(){ //do something    }; }; </script>
Before Click UI Thread time UI Queue
When Clicked UI Thread time UI Queue UI Update onclick UI Update
When Clicked UI Thread UI Update time UI Queue onclick Draw down state UI Update
When Clicked UI Thread onclick UI Update time UI Queue UI Update
When Clicked UI Thread onclick UI Update UI Update time UI Queue Draw up state
No UI updates while JavaScript is executing
JavaScript May Cause UI Update <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){    document.getElementById("btn").onclick = function(){        var div = document.createElement(“div”);        div.className = “tip”;        div.innerHTML = “You clicked me!”;        document.body.appendChild(div);    }; }; </script>
A UI update must use the latest info available
Long-running JavaScript=Unresponsive UI
Responsive UI UI Thread JavaScript UI Update UI Update time
Unresponsive UI UI Thread JavaScript UI Update UI Update time
The longer JavaScript runs,the worse the user experience
The runaway script timer prevents JavaScript from running for too long Each browser imposes its own limit (except Opera)
Internet Explorer
Firefox
Safari
Chrome
Runaway Script Timer Limits Internet Explorer: 5 million statements Firefox: 10 seconds Safari: 5 seconds Chrome: Unknown, hooks into normal crash control mechanism Opera: none
How Long Is Too Long? “0.1 second [100ms] 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
Translation:No single JavaScript job should execute for more than 100ms to ensure a responsive UI
Recommendation:Limit JavaScript execution to no more than 50msmeasured on IE6 :)
Does JIT compiling help?
Interpreted JavaScript UI Thread Interpret time
JITed JavaScript (1st Run) UI Thread Compile Execute time
JITed JavaScript (After 1st Run) UI Thread Execute time
Loadtime TechniquesDon't let JavaScript interfere with page load performance
During page load, JavaScript takes more time on the UI thread
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p> <script src="foo.js"></script>     <p>See ya!</p> </body> </html>
Result UI Thread JavaScript UI Update UI Update time
Result UI Thread foo.js See ya! Hello world! time
Result UI Thread Download See ya! Hello world! Parse Run time The UI thread needs to wait for the script to download, parse, and run before continuing
Result UI Thread Download See ya! Hello world! Parse Run Variable Constant Download time takes the longest and is variable
Translation:The page doesn't render while JavaScript is downloading, parsing, or executing during page load
<!doctype html> <html> <head>     <title>Example</title> </head> <body> <script src="foo.js"></script>     <p>Hello world!</p> <script src="bar.js"></script>     <p>See ya!</p> <script src="baz.js"></script>     <p>Uh oh!</p> </body> </html>
Result UI Thread JavaScript UI Update UI Update JavaScript JavaScript time The more scripts to download in between UI updates, the longer the page takes to render
Technique #1: Put scripts at the bottom
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p>     <p>See ya!</p> <script src="foo.js"></script> </body> </html>
Put Scripts at Bottom UI Thread JavaScript UI Update UI Update JavaScript JavaScript time Even if there are multiple scripts, the page renders quickly
Technique #2: Combine JavaScript files
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p>     <p>See ya!</p> <script src="foo.js"></script>     <script src="bar.js"></script>     <script src="baz.js"></script> </body> </html>
UI Thread JavaScript UI Update JavaScript JavaScript time Each script has overhead of downloading
UI Thread JavaScript UI Update time Combining all of the files limits the network overhead and gets scripts onto the page faster
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p>     <p>See ya!</p>    <script src="foo-and-bar-and-baz.js"></script> </body> </html>
Technique #3: Load scripts dynamically
Basic Technique var script = document.createElement("script"),     body; script.type = "text/javascript"; script.src = "foo.js"; body.insertBefore(script, body.firstChild); Dynamically loaded scripts are non-blocking
Downloads no longer block the UI thread
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p> <script src="foo.js"></script>     <p>See ya!</p> </body> </html>
Using HTML <script> UI Thread Download See ya! Hello world! Parse Run time
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p>     <script>     var script = document.createElement("script"),         body = document.body;     script.type = "text/javascript";     script.src = "foo.js";     body.insertBefore(script, body.firstChild);     </script>     <p>See ya!</p><!-- more content --> </body> </html>
Using Dynamic Scripts UI Thread See ya! Hello world! UI Update Run time Download Parse Only code execution happens on the UI thread, which means less blocking of UI updates
function loadScript(url, callback){var script = document.createElement("script"),    body = document.body;script.type = "text/javascript"; if (script.readyState){  //IE <= 8    script.onreadystatechange = function(){if (script.readyState == "loaded" ||                script.readyState == "complete"){            script.onreadystatechange = null;            callback();        }    };} else {  //Others    script.onload = function(){        callback();    };}script.src = url;body.insertBefore(script, body.firstChild); }
Usage loadScript("foo.js", function(){     alert("Loaded!"); });
Timing Note:Script execution begins immediately after download and parse – timing of execution is not guaranteed
Technique #4: Defer scripts
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p> <script defer src="foo.js"></script>     <p>See ya!</p>     <!-- even more markup --> </body> </html>
Support for <script defer> ? 5.0 3.5 7.0 4.0
Deferred scripts begin to download immediately, but don't execute until all UI updates complete
Using <script defer> UI Thread See ya! Hello world! More UI Run More UI time Download Parse Similar to dynamic script nodes, but with a guarantee that execution will happen last
Timing Note:Although scripts always execute after UI updates complete, the order of multiple <script defer> scripts is not guaranteed across browsers
Technique #5: Asynchronous scripts
<!doctype html> <html> <head>     <title>Example</title> </head> <body>     <p>Hello world!</p> <script async src="foo.js"></script>     <p>See ya!</p>     <!-- even more markup --> </body> </html>
Support for <script async> ? 5.0 3.6 7.0 10
Asynchronous scripts behave a lot like dynamic scripts
Using <script async> UI Thread See ya! Hello world! UI Update Run time Download Parse Download begins immediately and execution is slotted in at first available spot
Note:Order of execution is explicitly not preserved for asynchronous scripts
Runtime TechniquesWays to ensure JavaScript doesn't run away
function processArray(items, process, callback){ for (var i=0,len=items.length; i < len; i++){         process(items[i]);     }     callback(); }
Technique #1: Timers
//create a new timer and delay by 500ms setTimeout(function(){ //code to execute here }, 500); setTimeout() schedules a function to be added to the UI queue after a delay
function timedProcessArray(items, process, callback){ //create a clone of the original  var todo = items.concat();     setTimeout(function(){ var start = +new Date(); do {             process(todo.shift());         } while (todo.length > 0 &&              (+new Date() - start < 50)); if (todo.length > 0){             setTimeout(arguments.callee, 25);         } else {             callback(items);         }     }, 25); }
When Clicked UI Thread time UI Queue UI Update onclick UI Update
When Clicked UI Thread UI Update time UI Queue onclick UI Update
When Clicked UI Thread onclick UI Update time UI Queue UI Update
When Clicked UI Thread UI Update UI Update onclick time UI Queue
After 25ms UI Thread UI Update UI Update onclick time UI Queue JavaScript
After 25ms UI Thread JavaScript UI Update UI Update onclick time UI Queue
After Another 25ms UI Thread JavaScript UI Update UI Update onclick time UI Queue JavaScript
After Another 25ms UI Thread JavaScript JavaScript UI Update UI Update onclick time UI Queue
Technique #2: Script Yielding NEW!
//delay a function until after UI updates are done setImmediate(function(){ //code to execute here }); setImmediate() adds code to the UI queue after pending UI updates are finished
Support for Script Yielding ? ? ? ? 10 msSetIntermediate()
functionyieldingProcessArray(items, process, callback){ //create a clone of the originalvartodo = items.concat(); setImmediate(function(){ var start = +new Date(); do {             process(todo.shift());         } while (todo.length > 0 &&              (+new Date() - start < 50)); if (todo.length > 0){ setImmediate(arguments.callee);         } else {             callback(items);         } }); }
When Clicked UI Thread time UI Queue UI Update onclick UI Update
When Clicked UI Thread UI Update time UI Queue onclick UI Update
When Clicked UI Thread onclick UI Update time UI Queue UI Update
When Clicked UI Thread UI Update UI Update onclick time UI Queue
After Last UI Update UI Thread UI Update UI Update onclick time UI Queue JavaScript
After Last UI Update UI Thread JavaScript UI Update UI Update onclick time UI Queue
No Other UI Updates UI Thread JavaScript UI Update UI Update onclick time UI Queue JavaScript
No Other UI Updates UI Thread JavaScript JavaScript UI Update UI Update onclick time UI Queue
Technique #3: Web Workers
Support for Web Workers 10.6 4.0 3.5 4.0 10
Web Workers Asynchronous JavaScript execution Execution happens outside the UI thread Doesn’t block UI updates Data-Driven API Data is serialized going into and out of the worker No access to DOM or BOM Separate execution environment
//in page var worker = new Worker("process.js"); worker.onmessage = function(event){     useData(event.data); }; worker.postMessage(values); //in process.js self.onmessage = function(event){ var items = event.data; for (var i=0,len=items.length; i < len; i++){         process(items[i]);     }     self.postMessage(items); };
When Clicked UI Thread time UI Queue UI Update onclick UI Update
When Clicked UI Thread UI Update time UI Queue onclick UI Update
When Clicked UI Thread onclick UI Update time UI Queue UI Update
When Clicked UI Thread onclick UI Update time UI Queue Worker Thread UI Update
When Clicked UI Thread UI Update UI Update onclick time UI Queue Worker Thread JavaScript
Worker Thread Complete UI Thread UI Update UI Update onclick time UI Queue onmessage
Worker Thread Complete UI Thread onmessage UI Update UI Update onclick time UI Queue
Repaint and ReflowHidden performance costs of common operations
Long UI updates=Unresponsive UI
Unresponsive UI UI Thread JavaScript UI Update UI Update time
JavaScript can cause long UI updates by triggeringrepaint and reflow
A repaint occurs when a visual change doesn't require recalculation of layout Changes to visibility, colors (text/background), background images, etc.
Repaint <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){    document.getElementById("btn").onclick = function(){        this.style.color = "#ff0";    }; }; </script> Repaint!
A reflowoccurs when a visual change requires a change in layout Initial page load ▪ browser resize ▪ DOM structure change ▪ layout style change layout information retrieved
Reflow <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){    document.getElementById("btn").onclick = function(){        var div = document.createElement(“div”);        div.className = “tip”;        div.innerHTML = “You clicked me!”;        document.body.appendChild(div);    }; }; </script> Reflow!
Repaints and reflows are queued up as JavaScript executesand then executed in order
Reflow var list = document.getElementsByClassName("items")[0],     i, item; for (i=0; i < 10; i++){     item = document.createElement("li");     item.innerHTML = "Item #" + i; list.appendChild(item); } Reflow x 10!
Limiting repaints/reflows improves overall performance
Technique #1Perform DOM manipulations off-document
Off-Document Operations Fast because there's no repaint/reflow Techniques: Remove element from the document, make changes, insert back into document Set element's display to “none”, make changes, set display back to default Build up DOM changes on a DocumentFragment then apply all at once
DocumentFragment A document-like object Not visually represented Considered to be owned by the document from which it was created When passed to appendChild(), appends all of its children rather than itself
DocumentFragment var list = document.getElementsByClassName("items")[0],     fragment = document.createDocumentFragment(),     i, item; for (i=0; i < 10; i++){     item = document.createElement("li");     item.innerHTML = "Item #" + i;     fragment.appendChild(item); } list.appendChild(fragment); 1 Reflow
Technique #2Group Style Changes
Repaint! Reflow! element.style.color = "red"; element.style.height = "100px"; element.style.fontSize = "25px"; element.style.backgroundColor = "white"; Reflow! Repaint!
Grouping Style Changes .active {     color: red;     height: 100px;     fontSize: 25px;     background-color: white; } element.className = "active"; Reflow!
Grouping Style Changes var item = document.getElementById("myItem"); item.style.cssText = "color:red;height:100px;" +              "font-size:25px;background-color: white"); Reflow!
Technique #3Avoid Accidental Reflow
Accidental Reflow element.style.width= "100px"; var width = element.offsetWidth; Reflow!
What to do?  Minimize access to layout information offsetTop, offsetLeft, offsetWidth, offsetHeight scrollTop, scrollLeft, scrollWidth, scrollHeight clientTop, clientLeft, clientWidth, clientHeight Most computed styles  If a value is used more than once, store in local variable
Does hardware acceleration help?
Traditional Rendering UI Thread Compositing Drawing time
Hardware Acceleration UI Thread Prep Wait time Rendering info Signal complete Compositing Drawing GPU
Recap
The browser UI thread is responsible for both UI updates and JavaScript execution Only one can happen at a time
Responsive UI UI Thread JavaScript UI Update UI Update time

More Related Content

What's hot

High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010Nicholas Zakas
 
Front-end Automated Testing
Front-end Automated TestingFront-end Automated Testing
Front-end Automated TestingRuben Teijeiro
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010Nicholas Zakas
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End TestsSriram Angajala
 
High Performance Snippets
High Performance SnippetsHigh Performance Snippets
High Performance SnippetsSteve Souders
 
JavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and PerformanceJavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and PerformanceNicholas Zakas
 
Nightwatch at Tilt
Nightwatch at TiltNightwatch at Tilt
Nightwatch at TiltDave King
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Cogapp
 
20160905 - BrisJS - nightwatch testing
20160905 - BrisJS - nightwatch testing20160905 - BrisJS - nightwatch testing
20160905 - BrisJS - nightwatch testingVladimir Roudakov
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideMek Srunyu Stittri
 
Real World Selenium Testing
Real World Selenium TestingReal World Selenium Testing
Real World Selenium TestingMary Jo Sminkey
 
Introducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerIntroducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerApplitools
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016Gavin Pickin
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Andrew Eisenberg
 
Fullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterFullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterMek Srunyu Stittri
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015Matt Raible
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! HomepageNicholas Zakas
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using RubyKumari Warsha Goel
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScriptjeresig
 

What's hot (20)

High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010High Performance JavaScript - jQuery Conference SF Bay Area 2010
High Performance JavaScript - jQuery Conference SF Bay Area 2010
 
Front-end Automated Testing
Front-end Automated TestingFront-end Automated Testing
Front-end Automated Testing
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
High Performance Snippets
High Performance SnippetsHigh Performance Snippets
High Performance Snippets
 
JavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and PerformanceJavaScript Timers, Power Consumption, and Performance
JavaScript Timers, Power Consumption, and Performance
 
Nightwatch at Tilt
Nightwatch at TiltNightwatch at Tilt
Nightwatch at Tilt
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
20160905 - BrisJS - nightwatch testing
20160905 - BrisJS - nightwatch testing20160905 - BrisJS - nightwatch testing
20160905 - BrisJS - nightwatch testing
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
Real World Selenium Testing
Real World Selenium TestingReal World Selenium Testing
Real World Selenium Testing
 
Introducing Playwright's New Test Runner
Introducing Playwright's New Test RunnerIntroducing Playwright's New Test Runner
Introducing Playwright's New Test Runner
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Fullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterFullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year later
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScript
 

Viewers also liked

Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureNicholas Zakas
 
Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011Nicholas Zakas
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1Eric Wendelin
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript TestingScott Becker
 
Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceNicholas Zakas
 
AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)Nitya Narasimhan
 
Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Nicholas Zakas
 
The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014Matt Raible
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
Nicholas' Performance Talk at Google
Nicholas' Performance Talk at GoogleNicholas' Performance Talk at Google
Nicholas' Performance Talk at GoogleNicholas Zakas
 
JavaScript Variable Performance
JavaScript Variable PerformanceJavaScript Variable Performance
JavaScript Variable PerformanceNicholas Zakas
 
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Nicholas Zakas
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)Nicholas Zakas
 
Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)Nicholas Zakas
 
Mobile Web Speed Bumps
Mobile Web Speed BumpsMobile Web Speed Bumps
Mobile Web Speed BumpsNicholas Zakas
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Becoming Node.js ninja on Cloud Foundry
Becoming Node.js ninja on Cloud FoundryBecoming Node.js ninja on Cloud Foundry
Becoming Node.js ninja on Cloud FoundryRaja Rao DV
 

Viewers also liked (20)

Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
Maintainable JavaScript 2011
Maintainable JavaScript 2011Maintainable JavaScript 2011
Maintainable JavaScript 2011
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
Browser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom MenaceBrowser Wars Episode 1: The Phantom Menace
Browser Wars Episode 1: The Phantom Menace
 
AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)
 
Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)Enterprise JavaScript Error Handling (Ajax Experience 2008)
Enterprise JavaScript Error Handling (Ajax Experience 2008)
 
The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Nicholas' Performance Talk at Google
Nicholas' Performance Talk at GoogleNicholas' Performance Talk at Google
Nicholas' Performance Talk at Google
 
JavaScript Variable Performance
JavaScript Variable PerformanceJavaScript Variable Performance
JavaScript Variable Performance
 
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)
 
Responsive interfaces
Responsive interfacesResponsive interfaces
Responsive interfaces
 
Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)
 
Mobile Web Speed Bumps
Mobile Web Speed BumpsMobile Web Speed Bumps
Mobile Web Speed Bumps
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Becoming Node.js ninja on Cloud Foundry
Becoming Node.js ninja on Cloud FoundryBecoming Node.js ninja on Cloud Foundry
Becoming Node.js ninja on Cloud Foundry
 

Similar to High Performance JavaScript 2011

High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)Nicholas Zakas
 
High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)Nicholas Zakas
 
High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010Nicholas Zakas
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Steve Souders
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introductionTomi Juhola
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moondavejohnson
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance PatternsStoyan Stefanov
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web AppsTimothy Fisher
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran TochAdil Jafri
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentationmasudakram
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Timothy Fisher
 
SXSW: Even Faster Web Sites
SXSW: Even Faster Web SitesSXSW: Even Faster Web Sites
SXSW: Even Faster Web SitesSteve Souders
 
Google在Web前端方面的经验
Google在Web前端方面的经验Google在Web前端方面的经验
Google在Web前端方面的经验yiditushe
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersTodd Anglin
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 

Similar to High Performance JavaScript 2011 (20)

High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
 
High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)
 
High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010High Performance JavaScript - Fronteers 2010
High Performance JavaScript - Fronteers 2010
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moon
 
Extjs Howto
Extjs HowtoExtjs Howto
Extjs Howto
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
 
Selenium
SeleniumSelenium
Selenium
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentation
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Sxsw 20090314
Sxsw 20090314Sxsw 20090314
Sxsw 20090314
 
SXSW: Even Faster Web Sites
SXSW: Even Faster Web SitesSXSW: Even Faster Web Sites
SXSW: Even Faster Web Sites
 
Google在Web前端方面的经验
Google在Web前端方面的经验Google在Web前端方面的经验
Google在Web前端方面的经验
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 

More from Nicholas Zakas

Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!Nicholas Zakas
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Nicholas Zakas
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Nicholas Zakas
 
YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)Nicholas Zakas
 
Extreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI CompressorExtreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI CompressorNicholas Zakas
 
Writing Efficient JavaScript
Writing Efficient JavaScriptWriting Efficient JavaScript
Writing Efficient JavaScriptNicholas Zakas
 
Speed Up Your JavaScript
Speed Up Your JavaScriptSpeed Up Your JavaScript
Speed Up Your JavaScriptNicholas Zakas
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScriptNicholas Zakas
 
The New Yahoo! Homepage and YUI 3
The New Yahoo! Homepage and YUI 3The New Yahoo! Homepage and YUI 3
The New Yahoo! Homepage and YUI 3Nicholas Zakas
 

More from Nicholas Zakas (11)

Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
The Pointerless Web
The Pointerless WebThe Pointerless Web
The Pointerless Web
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)YUI Test The Next Generation (YUIConf 2010)
YUI Test The Next Generation (YUIConf 2010)
 
Extreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI CompressorExtreme JavaScript Compression With YUI Compressor
Extreme JavaScript Compression With YUI Compressor
 
Writing Efficient JavaScript
Writing Efficient JavaScriptWriting Efficient JavaScript
Writing Efficient JavaScript
 
Speed Up Your JavaScript
Speed Up Your JavaScriptSpeed Up Your JavaScript
Speed Up Your JavaScript
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScript
 
The New Yahoo! Homepage and YUI 3
The New Yahoo! Homepage and YUI 3The New Yahoo! Homepage and YUI 3
The New Yahoo! Homepage and YUI 3
 

Recently uploaded

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

High Performance JavaScript 2011

  • 1. High Performance JavaScript Nicholas C. Zakas| nczonline.net
  • 2. Who's this guy? Co-Creator csslint.net Contributor, Creator of YUI Test Ex-tech lead Yahoo! Author Lead Author Contributor Lead Author
  • 5.
  • 6.
  • 7.
  • 8. All browsers now haveoptimizing JavaScript engines Tracemonkey/ JaegarMonkey (3.5+) V8 (all) Nitro (4+) Chakra (9+) Karakan (10.5+)
  • 10. Old computers ran slow applications Small amounts of CPU power and memory
  • 11. New computers are generally faster but slow applications still exist More CPU + more memory = less disciplined application development
  • 12.
  • 13. Oh yeah, one more thing
  • 14.
  • 15.
  • 16.
  • 17. It's still possible to write slow JavaScript
  • 19. The UI Threadaka Browser Event Loop
  • 20. The browser UI thread is responsible for both UI updates and JavaScript execution Only one can happen at a time
  • 21. Jobs for UI updates and JavaScript execution are added to a UI queue Each job must wait in line for its turn to execute
  • 22. <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){ document.getElementById("btn").onclick = function(){ //do something }; }; </script>
  • 23. Before Click UI Thread time UI Queue
  • 24. When Clicked UI Thread time UI Queue UI Update onclick UI Update
  • 25. When Clicked UI Thread UI Update time UI Queue onclick Draw down state UI Update
  • 26. When Clicked UI Thread onclick UI Update time UI Queue UI Update
  • 27. When Clicked UI Thread onclick UI Update UI Update time UI Queue Draw up state
  • 28. No UI updates while JavaScript is executing
  • 29. JavaScript May Cause UI Update <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){ document.getElementById("btn").onclick = function(){ var div = document.createElement(“div”); div.className = “tip”; div.innerHTML = “You clicked me!”; document.body.appendChild(div); }; }; </script>
  • 30. A UI update must use the latest info available
  • 32. Responsive UI UI Thread JavaScript UI Update UI Update time
  • 33. Unresponsive UI UI Thread JavaScript UI Update UI Update time
  • 34. The longer JavaScript runs,the worse the user experience
  • 35. The runaway script timer prevents JavaScript from running for too long Each browser imposes its own limit (except Opera)
  • 40.
  • 41. Runaway Script Timer Limits Internet Explorer: 5 million statements Firefox: 10 seconds Safari: 5 seconds Chrome: Unknown, hooks into normal crash control mechanism Opera: none
  • 42. How Long Is Too Long? “0.1 second [100ms] 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
  • 43. Translation:No single JavaScript job should execute for more than 100ms to ensure a responsive UI
  • 44. Recommendation:Limit JavaScript execution to no more than 50msmeasured on IE6 :)
  • 46. Interpreted JavaScript UI Thread Interpret time
  • 47. JITed JavaScript (1st Run) UI Thread Compile Execute time
  • 48. JITed JavaScript (After 1st Run) UI Thread Execute time
  • 49. Loadtime TechniquesDon't let JavaScript interfere with page load performance
  • 50. During page load, JavaScript takes more time on the UI thread
  • 51. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <script src="foo.js"></script> <p>See ya!</p> </body> </html>
  • 52. Result UI Thread JavaScript UI Update UI Update time
  • 53. Result UI Thread foo.js See ya! Hello world! time
  • 54. Result UI Thread Download See ya! Hello world! Parse Run time The UI thread needs to wait for the script to download, parse, and run before continuing
  • 55. Result UI Thread Download See ya! Hello world! Parse Run Variable Constant Download time takes the longest and is variable
  • 56. Translation:The page doesn't render while JavaScript is downloading, parsing, or executing during page load
  • 57. <!doctype html> <html> <head> <title>Example</title> </head> <body> <script src="foo.js"></script> <p>Hello world!</p> <script src="bar.js"></script> <p>See ya!</p> <script src="baz.js"></script> <p>Uh oh!</p> </body> </html>
  • 58. Result UI Thread JavaScript UI Update UI Update JavaScript JavaScript time The more scripts to download in between UI updates, the longer the page takes to render
  • 59. Technique #1: Put scripts at the bottom
  • 60.
  • 61. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <p>See ya!</p> <script src="foo.js"></script> </body> </html>
  • 62. Put Scripts at Bottom UI Thread JavaScript UI Update UI Update JavaScript JavaScript time Even if there are multiple scripts, the page renders quickly
  • 63. Technique #2: Combine JavaScript files
  • 64. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <p>See ya!</p> <script src="foo.js"></script> <script src="bar.js"></script> <script src="baz.js"></script> </body> </html>
  • 65. UI Thread JavaScript UI Update JavaScript JavaScript time Each script has overhead of downloading
  • 66. UI Thread JavaScript UI Update time Combining all of the files limits the network overhead and gets scripts onto the page faster
  • 67. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <p>See ya!</p> <script src="foo-and-bar-and-baz.js"></script> </body> </html>
  • 68. Technique #3: Load scripts dynamically
  • 69. Basic Technique var script = document.createElement("script"), body; script.type = "text/javascript"; script.src = "foo.js"; body.insertBefore(script, body.firstChild); Dynamically loaded scripts are non-blocking
  • 70. Downloads no longer block the UI thread
  • 71. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <script src="foo.js"></script> <p>See ya!</p> </body> </html>
  • 72. Using HTML <script> UI Thread Download See ya! Hello world! Parse Run time
  • 73. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <script> var script = document.createElement("script"), body = document.body; script.type = "text/javascript"; script.src = "foo.js"; body.insertBefore(script, body.firstChild); </script> <p>See ya!</p><!-- more content --> </body> </html>
  • 74. Using Dynamic Scripts UI Thread See ya! Hello world! UI Update Run time Download Parse Only code execution happens on the UI thread, which means less blocking of UI updates
  • 75. function loadScript(url, callback){var script = document.createElement("script"), body = document.body;script.type = "text/javascript"; if (script.readyState){ //IE <= 8 script.onreadystatechange = function(){if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } };} else { //Others script.onload = function(){ callback(); };}script.src = url;body.insertBefore(script, body.firstChild); }
  • 76. Usage loadScript("foo.js", function(){ alert("Loaded!"); });
  • 77. Timing Note:Script execution begins immediately after download and parse – timing of execution is not guaranteed
  • 79. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <script defer src="foo.js"></script> <p>See ya!</p> <!-- even more markup --> </body> </html>
  • 80. Support for <script defer> ? 5.0 3.5 7.0 4.0
  • 81. Deferred scripts begin to download immediately, but don't execute until all UI updates complete
  • 82. Using <script defer> UI Thread See ya! Hello world! More UI Run More UI time Download Parse Similar to dynamic script nodes, but with a guarantee that execution will happen last
  • 83. Timing Note:Although scripts always execute after UI updates complete, the order of multiple <script defer> scripts is not guaranteed across browsers
  • 85. <!doctype html> <html> <head> <title>Example</title> </head> <body> <p>Hello world!</p> <script async src="foo.js"></script> <p>See ya!</p> <!-- even more markup --> </body> </html>
  • 86. Support for <script async> ? 5.0 3.6 7.0 10
  • 87. Asynchronous scripts behave a lot like dynamic scripts
  • 88. Using <script async> UI Thread See ya! Hello world! UI Update Run time Download Parse Download begins immediately and execution is slotted in at first available spot
  • 89. Note:Order of execution is explicitly not preserved for asynchronous scripts
  • 90. Runtime TechniquesWays to ensure JavaScript doesn't run away
  • 91. function processArray(items, process, callback){ for (var i=0,len=items.length; i < len; i++){ process(items[i]); } callback(); }
  • 93. //create a new timer and delay by 500ms setTimeout(function(){ //code to execute here }, 500); setTimeout() schedules a function to be added to the UI queue after a delay
  • 94. function timedProcessArray(items, process, callback){ //create a clone of the original var todo = items.concat(); setTimeout(function(){ var start = +new Date(); do { process(todo.shift()); } while (todo.length > 0 && (+new Date() - start < 50)); if (todo.length > 0){ setTimeout(arguments.callee, 25); } else { callback(items); } }, 25); }
  • 95. When Clicked UI Thread time UI Queue UI Update onclick UI Update
  • 96. When Clicked UI Thread UI Update time UI Queue onclick UI Update
  • 97. When Clicked UI Thread onclick UI Update time UI Queue UI Update
  • 98. When Clicked UI Thread UI Update UI Update onclick time UI Queue
  • 99. After 25ms UI Thread UI Update UI Update onclick time UI Queue JavaScript
  • 100. After 25ms UI Thread JavaScript UI Update UI Update onclick time UI Queue
  • 101. After Another 25ms UI Thread JavaScript UI Update UI Update onclick time UI Queue JavaScript
  • 102. After Another 25ms UI Thread JavaScript JavaScript UI Update UI Update onclick time UI Queue
  • 103. Technique #2: Script Yielding NEW!
  • 104.
  • 105. //delay a function until after UI updates are done setImmediate(function(){ //code to execute here }); setImmediate() adds code to the UI queue after pending UI updates are finished
  • 106. Support for Script Yielding ? ? ? ? 10 msSetIntermediate()
  • 107. functionyieldingProcessArray(items, process, callback){ //create a clone of the originalvartodo = items.concat(); setImmediate(function(){ var start = +new Date(); do { process(todo.shift()); } while (todo.length > 0 && (+new Date() - start < 50)); if (todo.length > 0){ setImmediate(arguments.callee); } else { callback(items); } }); }
  • 108. When Clicked UI Thread time UI Queue UI Update onclick UI Update
  • 109. When Clicked UI Thread UI Update time UI Queue onclick UI Update
  • 110. When Clicked UI Thread onclick UI Update time UI Queue UI Update
  • 111. When Clicked UI Thread UI Update UI Update onclick time UI Queue
  • 112. After Last UI Update UI Thread UI Update UI Update onclick time UI Queue JavaScript
  • 113. After Last UI Update UI Thread JavaScript UI Update UI Update onclick time UI Queue
  • 114. No Other UI Updates UI Thread JavaScript UI Update UI Update onclick time UI Queue JavaScript
  • 115. No Other UI Updates UI Thread JavaScript JavaScript UI Update UI Update onclick time UI Queue
  • 116. Technique #3: Web Workers
  • 117.
  • 118. Support for Web Workers 10.6 4.0 3.5 4.0 10
  • 119. Web Workers Asynchronous JavaScript execution Execution happens outside the UI thread Doesn’t block UI updates Data-Driven API Data is serialized going into and out of the worker No access to DOM or BOM Separate execution environment
  • 120. //in page var worker = new Worker("process.js"); worker.onmessage = function(event){ useData(event.data); }; worker.postMessage(values); //in process.js self.onmessage = function(event){ var items = event.data; for (var i=0,len=items.length; i < len; i++){ process(items[i]); } self.postMessage(items); };
  • 121. When Clicked UI Thread time UI Queue UI Update onclick UI Update
  • 122. When Clicked UI Thread UI Update time UI Queue onclick UI Update
  • 123. When Clicked UI Thread onclick UI Update time UI Queue UI Update
  • 124. When Clicked UI Thread onclick UI Update time UI Queue Worker Thread UI Update
  • 125. When Clicked UI Thread UI Update UI Update onclick time UI Queue Worker Thread JavaScript
  • 126. Worker Thread Complete UI Thread UI Update UI Update onclick time UI Queue onmessage
  • 127. Worker Thread Complete UI Thread onmessage UI Update UI Update onclick time UI Queue
  • 128. Repaint and ReflowHidden performance costs of common operations
  • 130. Unresponsive UI UI Thread JavaScript UI Update UI Update time
  • 131. JavaScript can cause long UI updates by triggeringrepaint and reflow
  • 132. A repaint occurs when a visual change doesn't require recalculation of layout Changes to visibility, colors (text/background), background images, etc.
  • 133. Repaint <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){ document.getElementById("btn").onclick = function(){ this.style.color = "#ff0"; }; }; </script> Repaint!
  • 134. A reflowoccurs when a visual change requires a change in layout Initial page load ▪ browser resize ▪ DOM structure change ▪ layout style change layout information retrieved
  • 135. Reflow <button id="btn" style="font-size: 30px; padding: 0.5em 1em">Click Me</button> <script type="text/javascript"> window.onload = function(){ document.getElementById("btn").onclick = function(){ var div = document.createElement(“div”); div.className = “tip”; div.innerHTML = “You clicked me!”; document.body.appendChild(div); }; }; </script> Reflow!
  • 136. Repaints and reflows are queued up as JavaScript executesand then executed in order
  • 137. Reflow var list = document.getElementsByClassName("items")[0], i, item; for (i=0; i < 10; i++){ item = document.createElement("li"); item.innerHTML = "Item #" + i; list.appendChild(item); } Reflow x 10!
  • 138. Limiting repaints/reflows improves overall performance
  • 139. Technique #1Perform DOM manipulations off-document
  • 140. Off-Document Operations Fast because there's no repaint/reflow Techniques: Remove element from the document, make changes, insert back into document Set element's display to “none”, make changes, set display back to default Build up DOM changes on a DocumentFragment then apply all at once
  • 141. DocumentFragment A document-like object Not visually represented Considered to be owned by the document from which it was created When passed to appendChild(), appends all of its children rather than itself
  • 142. DocumentFragment var list = document.getElementsByClassName("items")[0], fragment = document.createDocumentFragment(), i, item; for (i=0; i < 10; i++){ item = document.createElement("li"); item.innerHTML = "Item #" + i; fragment.appendChild(item); } list.appendChild(fragment); 1 Reflow
  • 144. Repaint! Reflow! element.style.color = "red"; element.style.height = "100px"; element.style.fontSize = "25px"; element.style.backgroundColor = "white"; Reflow! Repaint!
  • 145. Grouping Style Changes .active { color: red; height: 100px; fontSize: 25px; background-color: white; } element.className = "active"; Reflow!
  • 146. Grouping Style Changes var item = document.getElementById("myItem"); item.style.cssText = "color:red;height:100px;" + "font-size:25px;background-color: white"); Reflow!
  • 148. Accidental Reflow element.style.width= "100px"; var width = element.offsetWidth; Reflow!
  • 149. What to do? Minimize access to layout information offsetTop, offsetLeft, offsetWidth, offsetHeight scrollTop, scrollLeft, scrollWidth, scrollHeight clientTop, clientLeft, clientWidth, clientHeight Most computed styles If a value is used more than once, store in local variable
  • 151. Traditional Rendering UI Thread Compositing Drawing time
  • 152. Hardware Acceleration UI Thread Prep Wait time Rendering info Signal complete Compositing Drawing GPU
  • 153. Recap
  • 154. The browser UI thread is responsible for both UI updates and JavaScript execution Only one can happen at a time
  • 155. Responsive UI UI Thread JavaScript UI Update UI Update time
  • 156. Unresponsive UI UI Thread JavaScript UI Update UI Update time
  • 157. Unresponsive UI UI Thread JavaScript UI Update UI Update time
  • 158. Avoid Slow Loading JavaScript Dynamically created scripts Deferred scripts Asynchronous scripts
  • 159. Avoid Slow JavaScript Don't allow JavaScript to execute for more than 50ms Break up long JavaScript processes using: Timers Script Yielding (future) Web Workers
  • 160.
  • 161.
  • 162. Etcetera My blog: www.nczonline.net Twitter: @slicknet These Slides: slideshare.net/nzakas Hire us: projects@stubbornella.org
  • 164. Creative Commons Images Used http://www.flickr.com/photos/lrargerich/3115367361/ http://www.flickr.com/photos/hippie/2406411610/ http://www.flickr.com/photos/55733754@N00/3325000738/ http://www.flickr.com/photos/eurleif/255241547/ http://www.flickr.com/photos/off_the_wall/3444915939/ http://www.flickr.com/photos/wwarby/3296379139/ http://www.flickr.com/photos/derekgavey/4358797365/ http://www.flickr.com/photos/mulad/286641998/ http://www.flickr.com/photos/torley/2361164281/ http://www.flickr.com/photos/ottoman42/455242/ http://www.flickr.com/photos/goincase/3843348908/

Editor's Notes

  1. Over the past couple of years, we&apos;ve seen JavaScript development earn recognition as a true discipline. The idea that you should architect your code, use patterns and good programming practices has really elevated the role of the front end engineer. In my opinion, part of this elevation has been the adoption of what has traditionally been considered back end methodologies. We now focus on performance and algorithms, there&apos;s unit testing for JavaScript, and so much more. One of the areas that I&apos;ve seen a much slower than adoption that I&apos;d like is in the area of error handling.How many people have an error handling strategy for their backend? How many have dashboards that display problems with uptime and performance? How many have anything similar for the front end?Typically, the front end has been this black hole of information. You may get a few customer reports here and there, but you have no information about what&apos;s going on, how often it&apos;s occurring, or how many people have been affected.
  2. So what have we talked about? Maintainable JavaScript is made up of four components.First is Code Conventions that describe the format of the code you’re writing.Second is Loose Coupling – keeping HTML, JavaScript, and CSS on separate layers and keeping application logic out of event handlers.Third is Programming Practices that ensure your code is readable and easily debugged.Fourth is creating a Build Process