Top Banner
RICH AND SNAPPY APPS NO SCALING REQUIRED BY AMY HOY AND THOMAS FUCHS HTTP://SLASH7.COM/COMPANY ( )
53

Rich and Snappy Apps (No Scaling Required)

Jan 15, 2015

Download

Thomas Fuchs

Presentation by Amy Hoy and Thomas Fuchs about front-end web application performance at Kings of Code, Amsterdam, June 2009.

Main topics are loading-time performance, JavaScript tuning and progress indication.

Note that without the audio this is probably not very useful and it's mainly intended for attendees of the talk.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rich and Snappy Apps (No Scaling Required)

RICH AND SNAPPY APPS

NO SCALINGREQUIRED

BY AMY HOY AND THOMAS FUCHS

HTTP://SLASH7.COM/COMPANY

( )

Page 2: Rich and Snappy Apps (No Scaling Required)

@amyhoy @thomasfuchs

Page 3: Rich and Snappy Apps (No Scaling Required)

PERFORMA

NCE

Page 4: Rich and Snappy Apps (No Scaling Required)

“In A/B tests, we tried delaying the page in increments of 100 milliseconds and found that even very small delays would result in substantial and costly drops in revenue.”

Greg Linden, Amazon.com

Page 5: Rich and Snappy Apps (No Scaling Required)

Back-End10%

Front-End90%

(NOT SCIENTIFIC)

Page 6: Rich and Snappy Apps (No Scaling Required)

225+ PAGES

Page 7: Rich and Snappy Apps (No Scaling Required)

<!DOCTYPE “xmlns:xsl=’http://www.w3.org/1999/XSŁTransform’”><html xmlns:java_code=“xalan://gov.blahblah.build.Utils2”><head><META http-equiv=“Content-Type” content=“text/html; charset=UTF-8”><title>Blahblah - Home</title><!--SYSTEM DEFINED METADATA--><META content=“IE=7” http-equiv=“X-UA-Compatible”><META NAME=“CMS Document Id” CONTENT=“120186”><META NAME=“dc.title” CONTENT=“NASA - Home”><META NAME=“dc.format” CONTENT=“text/html”><META NAME=“dc.date.modified” CONTENT=“2009-06-27”><META NAME=“dc.language” CONTENT=“en”><META NAME=“dc.publisher” CONTENT=“Foobar”><META NAME=“dc.description” CONTENT=“”><META NAME=“dc.identifier” CONTENT=“http://www.blahblah.gov/home/index.html”><!--USER DEFINED METADATA--><META NAME=“dc.subject” CONTENT=“”><title>Blahblah - Home</title><!--Standard Includes--><script src=“/js/191918main_browser_message.js” type=“text/javascript” language=“javascript”></script><link type=“text/css” rel=“stylesheet” href=“/css/205608main_allmodules_homepage.css”><script language=“javascript” type=“text/javascript” src=“/templateimages/redesign/browser/js/conditionalBrowser.js”></script>

Page 8: Rich and Snappy Apps (No Scaling Required)

DOM MONSTER BOOKMARKLET

Page 9: Rich and Snappy Apps (No Scaling Required)

1. LOAD-TIME2. RUN-TIME3. FAKING IT

Page 10: Rich and Snappy Apps (No Scaling Required)

LOAD-TIME #1EXPIRATION

HEADERS

Page 11: Rich and Snappy Apps (No Scaling Required)
Page 12: Rich and Snappy Apps (No Scaling Required)

caching headers are goodbut expiration is wrong

Page 13: Rich and Snappy Apps (No Scaling Required)

LOAD-TIME #2CONCATENATION

Page 14: Rich and Snappy Apps (No Scaling Required)

optimized not so good

Page 15: Rich and Snappy Apps (No Scaling Required)

http://getsprockets.org

Page 16: Rich and Snappy Apps (No Scaling Required)

//= require <prototype>//= require “css”//= require “fx”

library_path/lib/prototype.js src/css.js src/fx.js

1 2 3

concatenated.js

Page 17: Rich and Snappy Apps (No Scaling Required)

concatenated.js concatenated.min.js

YUI Compressor

http://developer.yahoo.com/yui/compressor/

Page 18: Rich and Snappy Apps (No Scaling Required)

LOAD-TIME #3GZIP

Page 19: Rich and Snappy Apps (No Scaling Required)

.prototype

.

Page 20: Rich and Snappy Apps (No Scaling Required)

5.7X compression

138k

80k

24k

Original Minified Minified+GZIP

Page 21: Rich and Snappy Apps (No Scaling Required)

more than a second faster on a 1MBit

connection

Page 22: Rich and Snappy Apps (No Scaling Required)

1. LOAD-TIME2. RUN-TIME3. FAKING IT

Page 23: Rich and Snappy Apps (No Scaling Required)

RUN-TIME #1HTML

COMPLEXITY

Page 24: Rich and Snappy Apps (No Scaling Required)

source: http://tr.im/ffreflow

Page 25: Rich and Snappy Apps (No Scaling Required)

RUN-TIME #2INLINE

FUNCTION CALLS

Page 26: Rich and Snappy Apps (No Scaling Required)

function methodCall(){ function square(n){ return n*n }; var i=10000, sum = 0; while(i--) sum += square(i);}

function inlinedMethod(){ var i=10000, sum = 0; while(i--) sum += i*i;}

Page 27: Rich and Snappy Apps (No Scaling Required)

function methodCall(){ function square(n){ return n*n }; var i=10000, sum = 0; while(i--) sum += square(i);}

function inlinedMethod(){ var i=10000, sum = 0; while(i--) sum += i*i;}

Page 28: Rich and Snappy Apps (No Scaling Required)

function methodCall(){ function square(n){ return n*n }; var i=10000, sum = 0; while(i--) sum += square(i);}

function inlinedMethod(){ var i=10000, sum = 0; while(i--) sum += i*i;}

Page 29: Rich and Snappy Apps (No Scaling Required)

methodCall() inlinedMethod()

0.410s 0.150s

0.056s 0.045s

uhm, ahh, hmm† 0.128s

0.027s 0.016s

Page 30: Rich and Snappy Apps (No Scaling Required)

IE8 THROWS THIS WARNING AFTER 1SEC

Page 31: Rich and Snappy Apps (No Scaling Required)

RUN-TIME #3EMBRACE THE

LANGUAGE

Page 32: Rich and Snappy Apps (No Scaling Required)

function literals(){ var a = [], o = {};}

function classic(){ var a = new Array, o = new Object;}

Page 33: Rich and Snappy Apps (No Scaling Required)

classic() literals()

0.291s 0.265s

0.020s 0.016s

0.220s 0.185s

0.024s 0.010s

Page 34: Rich and Snappy Apps (No Scaling Required)

var string = ‘2’;

function implicit(){ return 1 * string;}

function explicit(){ return parseInt(string);}

Page 35: Rich and Snappy Apps (No Scaling Required)

explicit() implicit()

0.044s 0.054s

0.012s 0.004s

0.015s 0.036s

0.080s 0.060s

Page 36: Rich and Snappy Apps (No Scaling Required)

RUN-TIME #4GET RID OF LOOPS

Page 37: Rich and Snappy Apps (No Scaling Required)

function normalLoop(){ var i=60, j=0; while(i--) j++;}

Page 38: Rich and Snappy Apps (No Scaling Required)

function unrolledLoop(){ var j=0; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++; j++;}

Page 39: Rich and Snappy Apps (No Scaling Required)

normalLoop() unrolledLoop()

0.023s 0.010s

0.003s 0.001s

0.032s 0.015s

0.005s 0.001s

Page 40: Rich and Snappy Apps (No Scaling Required)

BEWARE OF ENGINE

DIFFERENCES

Page 41: Rich and Snappy Apps (No Scaling Required)

function test(){ return 1 * ‘2’;}

alert(test.toString());

Page 42: Rich and Snappy Apps (No Scaling Required)

function test(){ return 1 * ‘2’;}

alert(test.toString());

Page 43: Rich and Snappy Apps (No Scaling Required)

function test(){ return 1 * ‘2’;}

alert(test.toString());

Page 44: Rich and Snappy Apps (No Scaling Required)

1. LOAD-TIME2. RUN-TIME3. FAKING IT

Page 45: Rich and Snappy Apps (No Scaling Required)

... AND GRANT ME THE SERENITY TO

ACCEPT THE THINGS I CAN'T

Page 46: Rich and Snappy Apps (No Scaling Required)

USERS WAIT FOR 5-8 SECONDS BEFORE

GIVING UP

†Nah, F., "A study on tolerable waiting time: how long are Web users willing to wait?"Behaviour & Information Technology 23, no. 3 (2004): 153-163.

Page 47: Rich and Snappy Apps (No Scaling Required)

OR UP TO HALF A MINUTE WITH A

PROGRESS FEEDBACK

Page 48: Rich and Snappy Apps (No Scaling Required)
Page 49: Rich and Snappy Apps (No Scaling Required)
Page 50: Rich and Snappy Apps (No Scaling Required)
Page 51: Rich and Snappy Apps (No Scaling Required)
Page 52: Rich and Snappy Apps (No Scaling Required)

More inhttp://jsrocks.com

Page 53: Rich and Snappy Apps (No Scaling Required)

Q&ARICH AND SNAPPY APPS

BY AMY HOY AND THOMAS FUCHS

HTTP://SLASH7.COM/COMPANY