SlideShare a Scribd company logo
HOLISTIC
PERFORMANCE
   John Resig
Performance

Performance analysis is amazingly complex
  There is no, single, silver-bullet
Don’t want to compromise quality in favor of
performance
Also want to communicate the changes in a realistic
way
Analyzing Performance
Wall-clock time
  Time in different browsers
  CPU consumption
Memory consumption
  Memory leaks
Bandwidth consumption
  Parse time
Battery consumption (Mobile!)
Dictionary Lookups in
         JavaScript

An interesting example for looking at performance.
Most frequent concern: File Size
Many solutions only optimize for file size
  Disregard parse time, or other performance aspects
Naïve Solution

Pull in a raw list of words
Push it into an object for fast property lookups
Uses a lot of file size
Very fast lookups
Trie
A compact structure for
storing dictionaries
Optimizes heavily for file
size
Can be rather expensive
to parse
Can also use a lot of memory
File Size of Dictionaries


1100KB


 825KB


550KB


 275KB


  0KB
         Plain String Binary String Simple Trie Optimized Trie Suffix Trie Succinct Trie


                         Normal                          Gzipped
Load Speed of Dictionaries
            Time to load the dictionary once in Node.js on a 2.8 GHz Core i7.


 150ms


112.5ms


  75ms


37.5ms


  0ms
          Plain String Binary String        Hash            Trie      Succinct Trie
Search Speed of Dictionaries
                          Time to look up one word.


 6ms


4.5ms


 3ms


1.5ms


 0ms
        Plain String Binary String    Hash              Trie    Succinct Trie

                      Found                           Missing
Private Memory Usage of Dictionaries
                        After loading the dictionary once.


 11MB


8.25MB


 5.5MB


2.75MB


 0MB
         Plain String Binary String     Hash             Trie   Succinct Trie
dynaTrace
dynaTrace

One of the best tools available for analyzing the full
browser stack
Dig into CPU usage, bandwidth usage, and even
performance of browser-internal methods
Works in both IE and Firefox
Practical Performance

Think about the larger context
  Pre-optimization is dangerous
Code quality
Importance
Cross-browser compatibility
Performance in the
  jQuery Project
Rule 1: Prove it.
Prove it.

Any proposed performance optimization must be
undisputedly proven.
Show us the proposed changes and how it’ll affect
performance across all platforms.
How? JSPerf.
  http://jsperf.com/
JSPerf


JSPerf is a great tool
Makes it very easy to build a reproducible test:
  http://jsperf.com/valhooks-vs-val/2
Holistic JavaScript Performance
Holistic JavaScript Performance
JSPerf
JSPerf builds on some of the earlier analysis I did in
2008
  http://ejohn.org/blog/javascript-benchmark-quality/
Runs tests the maximum number of times in 5 seconds
Even does optimization to make sure there is less loop
overhead
Also uses a Java Applet for even better timer accuracy
Rule 2: See the Big Picture.
See the Big Picture.

Micro-optimizations are death.
Doesn’t matter how much you unroll a loop if that loop
is doing DOM manipulation.
Most crippling web app performance is from DOM
performance issues.
Pure JS performance is rarely an issue.
Prove the use case.

If you’re proposing an optimization you must prove
what it’ll help.
Show real world applications that’ll benefit from the
change.
This is especially important as it’ll help stop you from
wasting time on performance issues that don’t matter.
Rule 3: Clean Code.
Clean Code.
We won’t compromise our code quality in exchange for
performance.
Almost all code quality compromises come from
needless micro-optimizations.
~~(1 * string) vs. parseInt( string )
+new Date vs. (new Date).getTime()
Don’t even get me started on loop unrolling.
Rule 4: Don’t Slow IE.
Don’t Slow IE.

Just because performance gets better in one browser
doesn’t mean it’ll get faster in all browsers.
You shouldn’t compromise performance in other
browsers for the sake of one.
  (Unless that browser is IE, always improve IE
  performance.)
Communicating the Results


Creating realistic tests
Communicating in an effective manner
Creating Realistic Tests
Realism

It’s incredibly hard to create realistic test cases
It’s important to look at actual applications
We frequently use Google Code Search to find out how
people are using our APIs
  (This gives us the knowledge that we need when we
  want to deprecate an API as well.)
Communicating the Results
Browserscope
Collection of performance results
Organized by browser
JSPerf plugs right in
Creating Results


Pull the results directly from BrowserScope
Best: Compare old versions to new versions
  Within the context of all browsers
.val() (get)
                        (Number of test iterations, higher is better.)
700000




525000




350000




175000




    0

         Chrome 11 Safari 5    Firefox 4 Opera 11               IE 7     IE 8   IE 9
                                  1.5.2                            1.6
Competition
You might be inclined to compare performance against
other frameworks, libraries, applications, etc.
This tends to create more problems than it’s worth
  And the comparison isn’t always one-to-one
If competing, agree on some tests first
Work with your competition to create realistic tests
Compete Against Yourself
In the jQuery project we work to constantly improve
against ourselves
Every release we try to have some performance
improvements
  Always compare against our past releases
Rewriting API internals is a frequent way of getting
good performance results
More Information
Thank you!
http://ajax.dynatrace.com/ajax/en/
http://jsperf.com
http://www.browserscope.org
http://ejohn.org/blog/javascript-benchmark-quality/
http://ejohn.org/

More Related Content

PDF
New Features Coming in Browsers (RIT '09)
PDF
jQuery and the W3C
PDF
JavaScript development methodology
PDF
Integrating React.js Into a PHP Application
PDF
Web Development with NodeJS
PDF
High Performance JavaScript 2011
KEY
HTML5 vs Silverlight
PPTX
Automated Testing with Cucumber, PhantomJS and Selenium
New Features Coming in Browsers (RIT '09)
jQuery and the W3C
JavaScript development methodology
Integrating React.js Into a PHP Application
Web Development with NodeJS
High Performance JavaScript 2011
HTML5 vs Silverlight
Automated Testing with Cucumber, PhantomJS and Selenium

What's hot (20)

PDF
Why NodeJS
PPTX
PHP Indonesia - Nodejs Web Development
PDF
JS-IL: Getting MEAN in 1 Hour
PDF
Isomorphic React Applications: Performance And Scalability
PDF
Grokking #9: Building a real-time and offline editing service with Couchbase
PDF
React server side rendering performance
PDF
The fundamental problems of GUI applications and why people choose React
PDF
Capybara testing
PDF
MEAN Stack WeNode Barcelona Workshop
PDF
Module, AMD, RequireJS
PDF
NodeSummit - MEAN Stack
PDF
Modern Web Development in 2015
PDF
Writing Software not Code with Cucumber
PDF
Avoiding Common Pitfalls in Ember.js
ZIP
Drupal, Android and iPhone
PDF
Production optimization with React and Webpack
PPTX
Blazor - An Introduction
PDF
Web workers and service workers
PDF
JavaScript Web Workers
PDF
Testing Mobile JavaScript
Why NodeJS
PHP Indonesia - Nodejs Web Development
JS-IL: Getting MEAN in 1 Hour
Isomorphic React Applications: Performance And Scalability
Grokking #9: Building a real-time and offline editing service with Couchbase
React server side rendering performance
The fundamental problems of GUI applications and why people choose React
Capybara testing
MEAN Stack WeNode Barcelona Workshop
Module, AMD, RequireJS
NodeSummit - MEAN Stack
Modern Web Development in 2015
Writing Software not Code with Cucumber
Avoiding Common Pitfalls in Ember.js
Drupal, Android and iPhone
Production optimization with React and Webpack
Blazor - An Introduction
Web workers and service workers
JavaScript Web Workers
Testing Mobile JavaScript
Ad

Viewers also liked (6)

PDF
jQuery Mobile
PDF
jQuery Open Source Process (Knight Foundation 2011)
PDF
jQuery Recommendations to the W3C (2011)
PDF
Introduction to jQuery (Ajax Exp 2007)
PDF
Advanced jQuery (Ajax Exp 2007)
PDF
The zadu dicionary
jQuery Mobile
jQuery Open Source Process (Knight Foundation 2011)
jQuery Recommendations to the W3C (2011)
Introduction to jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
The zadu dicionary
Ad

Similar to Holistic JavaScript Performance (20)

PDF
Performance, Games, and Distributed Testing in JavaScript
PPT
Ajax Performance
PPT
Web performance essentials - Goodies
PPTX
JavaScript front end performance optimizations
PPT
Performance optimization - JavaScript
PPTX
Run Node Run
PPTX
Javascript best practices
PPTX
Performance on a budget
PPT
DevTools
PPTX
Dive into Angular, part 5: Experience
PDF
Comprehensive Performance Testing: From Early Dev to Live Production
PPTX
Performance is a Feature! at DDD 11
PPTX
Load testing with Visual Studio and Azure - Andrew Siemer
PPTX
Training - What is Performance ?
PDF
Performance Improvements In Browsers
PDF
Performance Improvements in Browsers
PPT
High Performance Ajax Applications 1197671494632682 2
PPT
High Performance Ajax Applications
PPTX
Accelerating Your Test Execution Pipeline
PDF
High Performance JavaScript Build Faster Web Application Interfaces 1st Editi...
Performance, Games, and Distributed Testing in JavaScript
Ajax Performance
Web performance essentials - Goodies
JavaScript front end performance optimizations
Performance optimization - JavaScript
Run Node Run
Javascript best practices
Performance on a budget
DevTools
Dive into Angular, part 5: Experience
Comprehensive Performance Testing: From Early Dev to Live Production
Performance is a Feature! at DDD 11
Load testing with Visual Studio and Azure - Andrew Siemer
Training - What is Performance ?
Performance Improvements In Browsers
Performance Improvements in Browsers
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications
Accelerating Your Test Execution Pipeline
High Performance JavaScript Build Faster Web Application Interfaces 1st Editi...

More from jeresig (20)

PDF
Does Coding Every Day Matter?
PDF
Accidentally Becoming a Digital Librarian
PDF
2014: John's Favorite Thing (Neo4j)
PDF
Computer Vision as Art Historical Investigation
PDF
Hacking Art History
PDF
Using JS to teach JS at Khan Academy
PDF
Applying Computer Vision to Art History
PDF
NYARC 2014: Frick/Zeri Results
PDF
EmpireJS: Hacking Art with Node js and Image Analysis
PDF
Applying Computer Vision to Art History
PDF
JavaScript Libraries (Ajax Exp 2006)
PDF
Introduction to jQuery (Ajax Exp 2006)
PDF
jQuery Open Source Process (RIT 2011)
PDF
jQuery Open Source (Fronteer 2011)
PDF
JavaScript Library Overview (Ajax Exp West 2007)
PDF
Meta Programming with JavaScript
PDF
Advancing JavaScript with Libraries (Yahoo Tech Talk)
PDF
The Future of JavaScript (Ajax Exp '07)
PDF
State of jQuery and Drupal
PDF
Khan Academy Computer Science
Does Coding Every Day Matter?
Accidentally Becoming a Digital Librarian
2014: John's Favorite Thing (Neo4j)
Computer Vision as Art Historical Investigation
Hacking Art History
Using JS to teach JS at Khan Academy
Applying Computer Vision to Art History
NYARC 2014: Frick/Zeri Results
EmpireJS: Hacking Art with Node js and Image Analysis
Applying Computer Vision to Art History
JavaScript Libraries (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
jQuery Open Source Process (RIT 2011)
jQuery Open Source (Fronteer 2011)
JavaScript Library Overview (Ajax Exp West 2007)
Meta Programming with JavaScript
Advancing JavaScript with Libraries (Yahoo Tech Talk)
The Future of JavaScript (Ajax Exp '07)
State of jQuery and Drupal
Khan Academy Computer Science

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Holistic JavaScript Performance

  • 1. HOLISTIC PERFORMANCE John Resig
  • 2. Performance Performance analysis is amazingly complex There is no, single, silver-bullet Don’t want to compromise quality in favor of performance Also want to communicate the changes in a realistic way
  • 3. Analyzing Performance Wall-clock time Time in different browsers CPU consumption Memory consumption Memory leaks Bandwidth consumption Parse time Battery consumption (Mobile!)
  • 4. Dictionary Lookups in JavaScript An interesting example for looking at performance. Most frequent concern: File Size Many solutions only optimize for file size Disregard parse time, or other performance aspects
  • 5. Naïve Solution Pull in a raw list of words Push it into an object for fast property lookups Uses a lot of file size Very fast lookups
  • 6. Trie A compact structure for storing dictionaries Optimizes heavily for file size Can be rather expensive to parse Can also use a lot of memory
  • 7. File Size of Dictionaries 1100KB 825KB 550KB 275KB 0KB Plain String Binary String Simple Trie Optimized Trie Suffix Trie Succinct Trie Normal Gzipped
  • 8. Load Speed of Dictionaries Time to load the dictionary once in Node.js on a 2.8 GHz Core i7. 150ms 112.5ms 75ms 37.5ms 0ms Plain String Binary String Hash Trie Succinct Trie
  • 9. Search Speed of Dictionaries Time to look up one word. 6ms 4.5ms 3ms 1.5ms 0ms Plain String Binary String Hash Trie Succinct Trie Found Missing
  • 10. Private Memory Usage of Dictionaries After loading the dictionary once. 11MB 8.25MB 5.5MB 2.75MB 0MB Plain String Binary String Hash Trie Succinct Trie
  • 12. dynaTrace One of the best tools available for analyzing the full browser stack Dig into CPU usage, bandwidth usage, and even performance of browser-internal methods Works in both IE and Firefox
  • 13. Practical Performance Think about the larger context Pre-optimization is dangerous Code quality Importance Cross-browser compatibility
  • 14. Performance in the jQuery Project
  • 16. Prove it. Any proposed performance optimization must be undisputedly proven. Show us the proposed changes and how it’ll affect performance across all platforms. How? JSPerf. http://jsperf.com/
  • 17. JSPerf JSPerf is a great tool Makes it very easy to build a reproducible test: http://jsperf.com/valhooks-vs-val/2
  • 20. JSPerf JSPerf builds on some of the earlier analysis I did in 2008 http://ejohn.org/blog/javascript-benchmark-quality/ Runs tests the maximum number of times in 5 seconds Even does optimization to make sure there is less loop overhead Also uses a Java Applet for even better timer accuracy
  • 21. Rule 2: See the Big Picture.
  • 22. See the Big Picture. Micro-optimizations are death. Doesn’t matter how much you unroll a loop if that loop is doing DOM manipulation. Most crippling web app performance is from DOM performance issues. Pure JS performance is rarely an issue.
  • 23. Prove the use case. If you’re proposing an optimization you must prove what it’ll help. Show real world applications that’ll benefit from the change. This is especially important as it’ll help stop you from wasting time on performance issues that don’t matter.
  • 24. Rule 3: Clean Code.
  • 25. Clean Code. We won’t compromise our code quality in exchange for performance. Almost all code quality compromises come from needless micro-optimizations. ~~(1 * string) vs. parseInt( string ) +new Date vs. (new Date).getTime() Don’t even get me started on loop unrolling.
  • 26. Rule 4: Don’t Slow IE.
  • 27. Don’t Slow IE. Just because performance gets better in one browser doesn’t mean it’ll get faster in all browsers. You shouldn’t compromise performance in other browsers for the sake of one. (Unless that browser is IE, always improve IE performance.)
  • 28. Communicating the Results Creating realistic tests Communicating in an effective manner
  • 30. Realism It’s incredibly hard to create realistic test cases It’s important to look at actual applications We frequently use Google Code Search to find out how people are using our APIs (This gives us the knowledge that we need when we want to deprecate an API as well.)
  • 32. Browserscope Collection of performance results Organized by browser JSPerf plugs right in
  • 33. Creating Results Pull the results directly from BrowserScope Best: Compare old versions to new versions Within the context of all browsers
  • 34. .val() (get) (Number of test iterations, higher is better.) 700000 525000 350000 175000 0 Chrome 11 Safari 5 Firefox 4 Opera 11 IE 7 IE 8 IE 9 1.5.2 1.6
  • 35. Competition You might be inclined to compare performance against other frameworks, libraries, applications, etc. This tends to create more problems than it’s worth And the comparison isn’t always one-to-one If competing, agree on some tests first Work with your competition to create realistic tests
  • 36. Compete Against Yourself In the jQuery project we work to constantly improve against ourselves Every release we try to have some performance improvements Always compare against our past releases Rewriting API internals is a frequent way of getting good performance results