SlideShare a Scribd company logo
1 of 48
High-Performance
JavaScript:
Why Everything You’ve
Been Taught is Wrong
Joseph Smarr
Plaxo, Inc.
Joseph Smarr, Plaxo, Inc.
About me
- Chief Platform Architect at Plaxo
- First employee (March 2002)
- Architect and lead developer for Plaxo Online
- Abusing web browsers since 1993 (Mosaic)
- Plaxo Online 2.0 (AJAX via iframes in 2004)
- JavaScript Wormhole (OSCON 06)
http://JosephSmarr.com
Joseph Smarr, Plaxo, Inc.
About Plaxo
- Smart Address Book
- Syncs address book and calendar with lots of places
- User updates their contact info  you get it automatically
- Founded in 2002, ~50 employees, 15M+ users
- Backed by Sequoia, Ram Shriram,Tim Koogle, et al
http://www.plaxo.com
Joseph Smarr, Plaxo, Inc.
Plaxo Online
AJAX Desktop
beta.plaxo.com
• Flexible desktop
• Contacts
• Calendar
• Tasks
• Notes
• Sync dashboard
• Pulse
• Profile / settings
Joseph Smarr, Plaxo, Inc.
Plaxo Online
AJAX Desktop
beta.plaxo.com
• Flexible desktop
• Contacts
• Calendar
• Tasks
• Notes
• Sync dashboard
• Pulse
• Profile / settings
Joseph Smarr, Plaxo, Inc.
Plaxo Online
AJAX Desktop
beta.plaxo.com
• Flexible desktop
• Contacts
• Calendar
• Tasks
• Notes
• Sync dashboard
• Pulse
• Profile / settings
Joseph Smarr, Plaxo, Inc.
Looks great…but it almost didn’t ship!
- Spring 06: “Let’s really push the envelope for Plaxo 3.0”
- Summer 06: “Wow, these are great UI ideas, keep em coming”
- Fall 06: “Let’s put 7 great web devs full time on this”’
- Winter 06: “Ok, we built a ton…now let’s optimize it, no problem”
- March 07: “Uh oh, making it fast is way harder than we thought”
- April 07: “We can’t ship this as is—do we need to start over?!?”
- June 07: “After a heroic effort, it’s just barely fast enough (phew!)”
Joseph Smarr, Plaxo, Inc.
Where did we go wrong??
- Didn’t take performance seriously from day one
- Didn’t think the browser’s limitations were significant
- Didn’t use the app daily as we were developing it
- Didn’t push back on feature requests for performance
- Didn’t value perceived performance / responsiveness
…overcoming these challenges required unlearning a lot of
standard assumptions about building software…
Joseph Smarr, Plaxo, Inc.
Why EverythingYou’ve Been Taught is Wrong
- AJAX euphoria
- Web browsers can be made to do anything now!
- Use desktop / OOP programming style
- Why it’s wrong
- Browsers are being pushed beyond their comfort zone
- JavaScript code is parsed & interpreted every time  cost per line
of source code
Joseph Smarr, Plaxo, Inc.
Why High-Performance JavaScript Matters
- Everyone is amazed by fast apps
- It hardly matters what else they do!
- Everyone hates slow apps
- It hardly matters what else they do…
- AJAX was supposed to be all about responsiveness!!
Having tried and almost failed, we now have a mantra:
Joseph Smarr, Plaxo, Inc.
The High-Performance JS Mantra
- Be Lazy
- Be Responsive
- Be Pragmatic
- BeVigilant
Joseph Smarr, Plaxo, Inc.
The High-Performance JS Mantra
- Be Lazy: Nothing is faster than doing nothing
- Be Responsive
- Be Pragmatic
- BeVigilant
Joseph Smarr, Plaxo, Inc.
Write less code
- Initial parsing of JavaScript is often a major bottleneck
- No JIT, no cached object code, interpreted every time
- Parse time is non-linear in the size of total JavaScript?
- Can’t rely on browser caching to excuse large code size
- Yahoo study: surprising number of hits with empty cache
- Frequent code releases  frequently need to re-download
- More code = more to download, execute, maintain, etc.
- Ideal for large AJAX apps is <500K JS uncompressed
Be Lazy: Nothing is faster than doing nothing
Joseph Smarr, Plaxo, Inc.
0
500
1,000
1,500
2,000
2,500
Zimbra Yahoo!
Mail
Plaxo
(before)
Renkoo Plaxo
(after)
Remember
the Milk
Meebo Gmail Google
Calendar
Plaxo
(startup)
JScodesize(KB,uncompressed)
Total code size of some AJAX apps
Joseph Smarr, Plaxo, Inc.
Write less code
- Minimize the JavaScript code you send down
- Minify = good, obfuscate = not much better
- Strip debug / logging lines (don’t just set log-level = 0)
- Remove unnecessary OOP boilerplate
- Get/Set functions don’t actually protect member vars! etc.
- Minimize dependency on third-party library code
- Lots of extra code comes along that you don’t need
- Libraries solve more general problems  use like scaffolding
Be Lazy: Nothing is faster than doing nothing
Joseph Smarr, Plaxo, Inc.
Load JavaScript on-demand
- Once you’ve written less code, load it only as-needed
- Break into classes / modules; use require / provide (ala dojo)
- Bundle classes into packages to minimize server round-trips
- Packages should ignore pre-loaded dependencies
- Tradeoff of downloading shared code twice vs.
multiple round trips (e.g. for common widgets)
- Build packages with error-handler hook for development
- Will re-build from source every time if you don’t write
Be Lazy: Nothing is faster than doing nothing
“I work hard at
being lazy”
“I work hard at
being lazy”
Ryan “Roger” Moore
Joseph Smarr, Plaxo, Inc.
Draw UI as late as possible
- Draw less DOM = faster to draw, browser less saturated
- Never pre-draw hidden UI if you can avoid it
- Cache previously drawn HTML when appropriate
- But have to know when to invalidate the cache
- Don’t keep hidden UI up-to-date behind the scenes
- Just re-draw next time you show it (simpler, one-time cost)
- Consider re-drawing vs. partial dynamic UI updates
- Redraw is often faster / easier / less code
Be Lazy: Nothing is faster than doing nothing
Joseph Smarr, Plaxo, Inc.
Never pre-draw hidden UI
Joseph Smarr, Plaxo, Inc.
Never pre-draw hidden UI
Joseph Smarr, Plaxo, Inc.
Never pre-draw hidden UI
Joseph Smarr, Plaxo, Inc.
Never pre-draw hidden UI
Joseph Smarr, Plaxo, Inc.
Never pre-draw hidden UI
Joseph Smarr, Plaxo, Inc.
How to Be Lazy
√ Write less code!
√ Load JS on-demand
√ Draw UI as late as possible
Be Lazy: Nothing is faster than doing nothing
Joseph Smarr, Plaxo, Inc.
The High-Performance JS Mantra
- Be Lazy
- Be Responsive: Jump when the user says jump
- Be Pragmatic
- BeVigilant
Joseph Smarr, Plaxo, Inc.
Minimize initial perceived load time
- Put CSS at the top of your page and JS at the bottom
- Draw major placeholder UI with “loading…” first
- Load / draw your app in stages (lazy, on-demand)
Be Responsive: Jump when the user says jump
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Load your app in stages
Joseph Smarr, Plaxo, Inc.
Yield early and often
- Always want to show a quick response acknowledgement
- But browser often doesn’t update UI until your code returns!
- Solution: do minimum work, use setTimeout(0) to yield
- Use closures to chain state together with periodic pauses
- Draw UI progressively, with loading messages as needed
- Use onmousedown instead of onclick (~100msec faster!)
- Demo: http://josephsmarr.com/oscon-js/yield.html
Be Responsive: Jump when the user says jump
Joseph Smarr, Plaxo, Inc.
Cache backend responses
- All data requests should go through data-manager code
- Request as needed and cache results for subsequent asks
- Requesting code always assumes async response
- Use range caches  only fill in missing pieces
- Ideal for partial views into long lists of data
- Balance local updates vs. re-fetching from APIs
- Do the easy cases, but beware of too much update code
- Worst case = trash cache and re-fetch = first-time case
Be Responsive: Jump when the user says jump
“Data structures and
AJAX—together at last!”
“Data structures and
AJAX—together at last!”
Glenn “Fiddich” Dixon
Joseph Smarr, Plaxo, Inc.
How to Be Responsive
√ Minimize initial perceived loading time
√ Yield early and often for responsive UI
√ Cache API responses with data-manager layer
Be Responsive: Jump when the user says jump
Joseph Smarr, Plaxo, Inc.
The High-Performance JS Mantra
- Be Lazy
- Be Responsive
- Be Pragmatic: Don’t make things even harder
- BeVigilant
Joseph Smarr, Plaxo, Inc.
Play to the browser’s strengths
- Avoid DOM manipulation; use innerHTML and array.join(“”)
- Avoid dynamic CSS-class definitions & CSS math
- Avoid reflow when possible (esp. manually on browser resize)
- Avoid memory allocation (e.g. string-splitting)
- Do DOM manipulation off-DOM, then re-insert at the end
Be Pragmatic: Don’t make things even harder
Joseph Smarr, Plaxo, Inc.
Cheat when you can / should
- Use global functions or IDs when reasonable
- Finding by class / attaching event handlers is slow
- Protect modularity only when needed (e.g. widgets)
- Directly attach onclick, etc. handlers instead of using event
listeners where appropriate
- Use fastest find-elems available when you need to scan the
DOM (don’t rely on general-purpose code)
Be Pragmatic: Don’t make things even harder
Joseph Smarr, Plaxo, Inc.
Inline initial API calls & HTML
- Tempting to load blank page and do everything in JavaScript
- Have to redraw UI dynamically; don’t want two copies of UI code
- Problem: initial load is usually too slow
- Too many round-trips to the server; too long before initial UI shows up
- Solution: if you have to do it every time, do it statically
- Save out initial API responses in web page
- Use data-manager to hide pre-fetching (can change your mind later)
- Download initial HTML in web page
Be Pragmatic: Don’t make things even harder
Joseph Smarr, Plaxo, Inc.
How to Be Pragmatic
√ Play to the browser’s strengths
√ Cheat when you can / should
√ Inline initial API calls / HTML for faster load time
Be Pragmatic: Don’t make things even harder
Joseph Smarr, Plaxo, Inc.
The High-Performance JS Mantra
- Be Lazy
- Be Responsive
- Be Pragmatic
- BeVigilant: Only you can prevent slow web apps
Joseph Smarr, Plaxo, Inc.
Profile like crazy
- Bottlenecks abound and are usually not obvious
- Use firebug’s profiler (Joe Hewitt, you rule! )
- Use timestamp diffs and alerts
- Comment-out blocks of code
- Measure with a consistent environment
- Browsers bog down  always restart first
- Try multiple runs and average (and don’t forget the cache)
Be Vigilant: Only you can prevent slow web apps
Joseph Smarr, Plaxo, Inc.
Firebug is your friend
Joseph Smarr, Plaxo, Inc.
Consider performance from day one
- Apps get slow when you make them do many / slow things!
- Consider how much code / work is needed for each feature
- Is it making the browser work against the grain?
- What else is suffering for this feature? Is it worth it?
- Make sure everyone remembers how important speed is
Be Vigilant: Only you can prevent slow web apps
Joseph Smarr, Plaxo, Inc.
- Building high-performance apps requires the right attitude
- Must consider and prioritize speed in every decision
- Ask “what features can I add within this size / speed?” vs.“how
small / fast can I get this set of features?”
- I had to learn this the hard way
(Plaxo 3.0 almost didn’t ship!)
Get your priorities straight
Be Vigilant: Only you can prevent slow web apps
“Performance first,
features second!”
“Performance first,
features second!”
Todd & Cam
Joseph Smarr, Plaxo, Inc.
How to BeVigilant
√ Profile like crazy
√ Consider performance from day one
√ Get your priorities straight
Be Vigilant: Only you can prevent slow web apps
Joseph Smarr, Plaxo, Inc.
Conclusion:
Avoid making the same mistakes we did
- Make the browser happy … and it will make you happy
- Web browsers are more like mobile phones than desktops
- Limited, flimsy, temperamental platform being stretched beyond its
initial design goals
- But everyone’s got one, so it’s still the best place to be
- Don’t push the limits unless you have to
- Often, small quick-loading pages with AJAX interactions is best
- Sometimes you really do need rich, interactive controls
Joseph Smarr, Plaxo, Inc.
Just Remember:
EverythingYou’ve Been Taught is Wrong
- Think about performance — early and often
- Write as little code as you need — each line has a cost
- Do what the browser wants (whenever possible)
- Remember the high-performance JavaScript mantra:
- Be lazy
- Be responsive
- Be pragmatic
- Be vigilant
http://JosephSmarr.com

More Related Content

What's hot

What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012WordCamp Sydney
 
Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016Matt Raible
 
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105 Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105 Christian Heilmann
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performancedmethvin
 
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...Ezra Gildesgame
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYExtreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYMaximiliano Firtman
 
Testing Single Page Webapp
Testing Single Page WebappTesting Single Page Webapp
Testing Single Page WebappAkshay Mathur
 
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
 
Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Matt Raible
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScriptjeresig
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015Matt Raible
 
On Selecting JavaScript Frameworks (Women Who Code 10/15)
On Selecting JavaScript Frameworks (Women Who Code 10/15)On Selecting JavaScript Frameworks (Women Who Code 10/15)
On Selecting JavaScript Frameworks (Women Who Code 10/15)Zoe Landon
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016Matt Raible
 
Optimizing Your Site for Holiday Traffic
Optimizing Your Site for Holiday TrafficOptimizing Your Site for Holiday Traffic
Optimizing Your Site for Holiday TrafficWP Engine UK
 
New Perspectives on Performance
New Perspectives on PerformanceNew Perspectives on Performance
New Perspectives on Performancemennovanslooten
 
Kickstarter Your Node.JS Application
Kickstarter Your Node.JS ApplicationKickstarter Your Node.JS Application
Kickstarter Your Node.JS ApplicationHengki Sihombing
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSChristian Heilmann
 
Build the mobile web you want
Build the mobile web you wantBuild the mobile web you want
Build the mobile web you wantk88hudson
 

What's hot (20)

What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
 
Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016
 
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105 Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
 
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYExtreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NY
 
Testing Single Page Webapp
Testing Single Page WebappTesting Single Page Webapp
Testing Single Page Webapp
 
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
 
Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
 
Testing Mobile JavaScript
Testing Mobile JavaScriptTesting Mobile JavaScript
Testing Mobile JavaScript
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
 
On Selecting JavaScript Frameworks (Women Who Code 10/15)
On Selecting JavaScript Frameworks (Women Who Code 10/15)On Selecting JavaScript Frameworks (Women Who Code 10/15)
On Selecting JavaScript Frameworks (Women Who Code 10/15)
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
 
WAG the Blog
WAG the BlogWAG the Blog
WAG the Blog
 
Optimizing Your Site for Holiday Traffic
Optimizing Your Site for Holiday TrafficOptimizing Your Site for Holiday Traffic
Optimizing Your Site for Holiday Traffic
 
New Perspectives on Performance
New Perspectives on PerformanceNew Perspectives on Performance
New Perspectives on Performance
 
Kickstarter Your Node.JS Application
Kickstarter Your Node.JS ApplicationKickstarter Your Node.JS Application
Kickstarter Your Node.JS Application
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJS
 
12-2015-Meetup
12-2015-Meetup12-2015-Meetup
12-2015-Meetup
 
Build the mobile web you want
Build the mobile web you wantBuild the mobile web you want
Build the mobile web you want
 

Similar to High performance java script why everything youve been taught is wrong

Smarr Oscon 2007
Smarr Oscon 2007Smarr Oscon 2007
Smarr Oscon 2007briandemant
 
High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)Nicholas Zakas
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web AppsTimothy Fisher
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moondavejohnson
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS UniverseStefano Di Paola
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)danwrong
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeRadosław Scheibinger
 
Lesson learned from 3 years with hybrid apps
Lesson learned from 3 years with hybrid appsLesson learned from 3 years with hybrid apps
Lesson learned from 3 years with hybrid appsPatrik Malmquist
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksServerlessConf
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)danwrong
 
Performance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For SpeedPerformance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For SpeedVijay Rayapati
 
How to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fpsHow to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fpsIntexSoft
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moiblemarkuskobler
 
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014Maximiliano Firtman
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeededm00se
 

Similar to High performance java script why everything youve been taught is wrong (20)

Smarr Oscon 2007
Smarr Oscon 2007Smarr Oscon 2007
Smarr Oscon 2007
 
Os Smarr
Os SmarrOs Smarr
Os Smarr
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)High Performance JavaScript (YUIConf 2010)
High Performance JavaScript (YUIConf 2010)
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Web assembly with PWA
Web assembly with PWA Web assembly with PWA
Web assembly with PWA
 
Ajax to the Moon
Ajax to the MoonAjax to the Moon
Ajax to the Moon
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
Lesson learned from 3 years with hybrid apps
Lesson learned from 3 years with hybrid appsLesson learned from 3 years with hybrid apps
Lesson learned from 3 years with hybrid apps
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New Tricks
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)
 
The PRPL Pattern
The PRPL PatternThe PRPL Pattern
The PRPL Pattern
 
Performance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For SpeedPerformance Tuning Web Apps - The Need For Speed
Performance Tuning Web Apps - The Need For Speed
 
How to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fpsHow to write an application and not roll down to 1 fps
How to write an application and not roll down to 1 fps
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moible
 
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
 

Recently uploaded

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
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
 
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
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

High performance java script why everything youve been taught is wrong

  • 1. High-Performance JavaScript: Why Everything You’ve Been Taught is Wrong Joseph Smarr Plaxo, Inc.
  • 2. Joseph Smarr, Plaxo, Inc. About me - Chief Platform Architect at Plaxo - First employee (March 2002) - Architect and lead developer for Plaxo Online - Abusing web browsers since 1993 (Mosaic) - Plaxo Online 2.0 (AJAX via iframes in 2004) - JavaScript Wormhole (OSCON 06) http://JosephSmarr.com
  • 3. Joseph Smarr, Plaxo, Inc. About Plaxo - Smart Address Book - Syncs address book and calendar with lots of places - User updates their contact info  you get it automatically - Founded in 2002, ~50 employees, 15M+ users - Backed by Sequoia, Ram Shriram,Tim Koogle, et al http://www.plaxo.com
  • 4. Joseph Smarr, Plaxo, Inc. Plaxo Online AJAX Desktop beta.plaxo.com • Flexible desktop • Contacts • Calendar • Tasks • Notes • Sync dashboard • Pulse • Profile / settings
  • 5. Joseph Smarr, Plaxo, Inc. Plaxo Online AJAX Desktop beta.plaxo.com • Flexible desktop • Contacts • Calendar • Tasks • Notes • Sync dashboard • Pulse • Profile / settings
  • 6. Joseph Smarr, Plaxo, Inc. Plaxo Online AJAX Desktop beta.plaxo.com • Flexible desktop • Contacts • Calendar • Tasks • Notes • Sync dashboard • Pulse • Profile / settings
  • 7. Joseph Smarr, Plaxo, Inc. Looks great…but it almost didn’t ship! - Spring 06: “Let’s really push the envelope for Plaxo 3.0” - Summer 06: “Wow, these are great UI ideas, keep em coming” - Fall 06: “Let’s put 7 great web devs full time on this”’ - Winter 06: “Ok, we built a ton…now let’s optimize it, no problem” - March 07: “Uh oh, making it fast is way harder than we thought” - April 07: “We can’t ship this as is—do we need to start over?!?” - June 07: “After a heroic effort, it’s just barely fast enough (phew!)”
  • 8. Joseph Smarr, Plaxo, Inc. Where did we go wrong?? - Didn’t take performance seriously from day one - Didn’t think the browser’s limitations were significant - Didn’t use the app daily as we were developing it - Didn’t push back on feature requests for performance - Didn’t value perceived performance / responsiveness …overcoming these challenges required unlearning a lot of standard assumptions about building software…
  • 9. Joseph Smarr, Plaxo, Inc. Why EverythingYou’ve Been Taught is Wrong - AJAX euphoria - Web browsers can be made to do anything now! - Use desktop / OOP programming style - Why it’s wrong - Browsers are being pushed beyond their comfort zone - JavaScript code is parsed & interpreted every time  cost per line of source code
  • 10. Joseph Smarr, Plaxo, Inc. Why High-Performance JavaScript Matters - Everyone is amazed by fast apps - It hardly matters what else they do! - Everyone hates slow apps - It hardly matters what else they do… - AJAX was supposed to be all about responsiveness!! Having tried and almost failed, we now have a mantra:
  • 11. Joseph Smarr, Plaxo, Inc. The High-Performance JS Mantra - Be Lazy - Be Responsive - Be Pragmatic - BeVigilant
  • 12. Joseph Smarr, Plaxo, Inc. The High-Performance JS Mantra - Be Lazy: Nothing is faster than doing nothing - Be Responsive - Be Pragmatic - BeVigilant
  • 13. Joseph Smarr, Plaxo, Inc. Write less code - Initial parsing of JavaScript is often a major bottleneck - No JIT, no cached object code, interpreted every time - Parse time is non-linear in the size of total JavaScript? - Can’t rely on browser caching to excuse large code size - Yahoo study: surprising number of hits with empty cache - Frequent code releases  frequently need to re-download - More code = more to download, execute, maintain, etc. - Ideal for large AJAX apps is <500K JS uncompressed Be Lazy: Nothing is faster than doing nothing
  • 14. Joseph Smarr, Plaxo, Inc. 0 500 1,000 1,500 2,000 2,500 Zimbra Yahoo! Mail Plaxo (before) Renkoo Plaxo (after) Remember the Milk Meebo Gmail Google Calendar Plaxo (startup) JScodesize(KB,uncompressed) Total code size of some AJAX apps
  • 15. Joseph Smarr, Plaxo, Inc. Write less code - Minimize the JavaScript code you send down - Minify = good, obfuscate = not much better - Strip debug / logging lines (don’t just set log-level = 0) - Remove unnecessary OOP boilerplate - Get/Set functions don’t actually protect member vars! etc. - Minimize dependency on third-party library code - Lots of extra code comes along that you don’t need - Libraries solve more general problems  use like scaffolding Be Lazy: Nothing is faster than doing nothing
  • 16. Joseph Smarr, Plaxo, Inc. Load JavaScript on-demand - Once you’ve written less code, load it only as-needed - Break into classes / modules; use require / provide (ala dojo) - Bundle classes into packages to minimize server round-trips - Packages should ignore pre-loaded dependencies - Tradeoff of downloading shared code twice vs. multiple round trips (e.g. for common widgets) - Build packages with error-handler hook for development - Will re-build from source every time if you don’t write Be Lazy: Nothing is faster than doing nothing “I work hard at being lazy” “I work hard at being lazy” Ryan “Roger” Moore
  • 17. Joseph Smarr, Plaxo, Inc. Draw UI as late as possible - Draw less DOM = faster to draw, browser less saturated - Never pre-draw hidden UI if you can avoid it - Cache previously drawn HTML when appropriate - But have to know when to invalidate the cache - Don’t keep hidden UI up-to-date behind the scenes - Just re-draw next time you show it (simpler, one-time cost) - Consider re-drawing vs. partial dynamic UI updates - Redraw is often faster / easier / less code Be Lazy: Nothing is faster than doing nothing
  • 18. Joseph Smarr, Plaxo, Inc. Never pre-draw hidden UI
  • 19. Joseph Smarr, Plaxo, Inc. Never pre-draw hidden UI
  • 20. Joseph Smarr, Plaxo, Inc. Never pre-draw hidden UI
  • 21. Joseph Smarr, Plaxo, Inc. Never pre-draw hidden UI
  • 22. Joseph Smarr, Plaxo, Inc. Never pre-draw hidden UI
  • 23. Joseph Smarr, Plaxo, Inc. How to Be Lazy √ Write less code! √ Load JS on-demand √ Draw UI as late as possible Be Lazy: Nothing is faster than doing nothing
  • 24. Joseph Smarr, Plaxo, Inc. The High-Performance JS Mantra - Be Lazy - Be Responsive: Jump when the user says jump - Be Pragmatic - BeVigilant
  • 25. Joseph Smarr, Plaxo, Inc. Minimize initial perceived load time - Put CSS at the top of your page and JS at the bottom - Draw major placeholder UI with “loading…” first - Load / draw your app in stages (lazy, on-demand) Be Responsive: Jump when the user says jump
  • 26. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 27. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 28. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 29. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 30. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 31. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 32. Joseph Smarr, Plaxo, Inc. Load your app in stages
  • 33. Joseph Smarr, Plaxo, Inc. Yield early and often - Always want to show a quick response acknowledgement - But browser often doesn’t update UI until your code returns! - Solution: do minimum work, use setTimeout(0) to yield - Use closures to chain state together with periodic pauses - Draw UI progressively, with loading messages as needed - Use onmousedown instead of onclick (~100msec faster!) - Demo: http://josephsmarr.com/oscon-js/yield.html Be Responsive: Jump when the user says jump
  • 34. Joseph Smarr, Plaxo, Inc. Cache backend responses - All data requests should go through data-manager code - Request as needed and cache results for subsequent asks - Requesting code always assumes async response - Use range caches  only fill in missing pieces - Ideal for partial views into long lists of data - Balance local updates vs. re-fetching from APIs - Do the easy cases, but beware of too much update code - Worst case = trash cache and re-fetch = first-time case Be Responsive: Jump when the user says jump “Data structures and AJAX—together at last!” “Data structures and AJAX—together at last!” Glenn “Fiddich” Dixon
  • 35. Joseph Smarr, Plaxo, Inc. How to Be Responsive √ Minimize initial perceived loading time √ Yield early and often for responsive UI √ Cache API responses with data-manager layer Be Responsive: Jump when the user says jump
  • 36. Joseph Smarr, Plaxo, Inc. The High-Performance JS Mantra - Be Lazy - Be Responsive - Be Pragmatic: Don’t make things even harder - BeVigilant
  • 37. Joseph Smarr, Plaxo, Inc. Play to the browser’s strengths - Avoid DOM manipulation; use innerHTML and array.join(“”) - Avoid dynamic CSS-class definitions & CSS math - Avoid reflow when possible (esp. manually on browser resize) - Avoid memory allocation (e.g. string-splitting) - Do DOM manipulation off-DOM, then re-insert at the end Be Pragmatic: Don’t make things even harder
  • 38. Joseph Smarr, Plaxo, Inc. Cheat when you can / should - Use global functions or IDs when reasonable - Finding by class / attaching event handlers is slow - Protect modularity only when needed (e.g. widgets) - Directly attach onclick, etc. handlers instead of using event listeners where appropriate - Use fastest find-elems available when you need to scan the DOM (don’t rely on general-purpose code) Be Pragmatic: Don’t make things even harder
  • 39. Joseph Smarr, Plaxo, Inc. Inline initial API calls & HTML - Tempting to load blank page and do everything in JavaScript - Have to redraw UI dynamically; don’t want two copies of UI code - Problem: initial load is usually too slow - Too many round-trips to the server; too long before initial UI shows up - Solution: if you have to do it every time, do it statically - Save out initial API responses in web page - Use data-manager to hide pre-fetching (can change your mind later) - Download initial HTML in web page Be Pragmatic: Don’t make things even harder
  • 40. Joseph Smarr, Plaxo, Inc. How to Be Pragmatic √ Play to the browser’s strengths √ Cheat when you can / should √ Inline initial API calls / HTML for faster load time Be Pragmatic: Don’t make things even harder
  • 41. Joseph Smarr, Plaxo, Inc. The High-Performance JS Mantra - Be Lazy - Be Responsive - Be Pragmatic - BeVigilant: Only you can prevent slow web apps
  • 42. Joseph Smarr, Plaxo, Inc. Profile like crazy - Bottlenecks abound and are usually not obvious - Use firebug’s profiler (Joe Hewitt, you rule! ) - Use timestamp diffs and alerts - Comment-out blocks of code - Measure with a consistent environment - Browsers bog down  always restart first - Try multiple runs and average (and don’t forget the cache) Be Vigilant: Only you can prevent slow web apps
  • 43. Joseph Smarr, Plaxo, Inc. Firebug is your friend
  • 44. Joseph Smarr, Plaxo, Inc. Consider performance from day one - Apps get slow when you make them do many / slow things! - Consider how much code / work is needed for each feature - Is it making the browser work against the grain? - What else is suffering for this feature? Is it worth it? - Make sure everyone remembers how important speed is Be Vigilant: Only you can prevent slow web apps
  • 45. Joseph Smarr, Plaxo, Inc. - Building high-performance apps requires the right attitude - Must consider and prioritize speed in every decision - Ask “what features can I add within this size / speed?” vs.“how small / fast can I get this set of features?” - I had to learn this the hard way (Plaxo 3.0 almost didn’t ship!) Get your priorities straight Be Vigilant: Only you can prevent slow web apps “Performance first, features second!” “Performance first, features second!” Todd & Cam
  • 46. Joseph Smarr, Plaxo, Inc. How to BeVigilant √ Profile like crazy √ Consider performance from day one √ Get your priorities straight Be Vigilant: Only you can prevent slow web apps
  • 47. Joseph Smarr, Plaxo, Inc. Conclusion: Avoid making the same mistakes we did - Make the browser happy … and it will make you happy - Web browsers are more like mobile phones than desktops - Limited, flimsy, temperamental platform being stretched beyond its initial design goals - But everyone’s got one, so it’s still the best place to be - Don’t push the limits unless you have to - Often, small quick-loading pages with AJAX interactions is best - Sometimes you really do need rich, interactive controls
  • 48. Joseph Smarr, Plaxo, Inc. Just Remember: EverythingYou’ve Been Taught is Wrong - Think about performance — early and often - Write as little code as you need — each line has a cost - Do what the browser wants (whenever possible) - Remember the high-performance JavaScript mantra: - Be lazy - Be responsive - Be pragmatic - Be vigilant http://JosephSmarr.com

Editor's Notes

  1. IOW, The assumptions made in traditional desktop/OOP programming environments don’t transfer to the JavaScript/web environment.
  2. TiVo is a great example: immediate audio / visual feedback, even for slow tasks
  3. For find elems: specify node type and class name, don’t use substring, and return immediately if you only want one elem back
  4. e.g. CPU parse time vs. download time for large JS files!