620 likes | 768 Views
Building A Fast Web Experience. Internet Explorer 9 Is All Around Fast. Sandeep J Alur Microsoft India. Expectations are Rising for the Web. The capabilities of the web are increasing every day, but the way we experience the web isn’t keeping up. Agenda.
E N D
Building A Fast Web Experience Internet Explorer 9 Is All Around Fast Sandeep J Alur Microsoft India
Expectations are Rising for the Web The capabilities of the web are increasing every day, but the way we experience the web isn’t keeping up.
Agenda Case Study - The Wall Street Journal The Browser Subsystems Deep Dive – Network and Caching Subsystem Deep Dive – JavaScript Engine Deep Dive – Hardware Accelerated HTML5
Browser Subsystems • Rendering • Layout • Block Building • Formatting • DOM • Marshalling • JavaScript • Collections • CSS • HTML • Networking
Picking Five Popular News Sites Wall Street Journal Chicago Tribune USA Today New York Times Washington Post CNN News Seattle Times MSN News Financial Times Boston Globe News Site #1 News Site #2 News Site #3 News Site #4 News Site #5
Five Popular News Sites JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Five Popular News Sites Variation in Total Size JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Five Popular News Sites Number Elements to Number of CSS Rules JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Five Popular News Sites Number of Images JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Five Popular News Sites Amount of JavaScript JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Five Popular News Sites Amount of JavaScript JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Which sites loads the fastest? JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Which sites loads the slowest? JQuery YUI Prototype MooTools Scriptaculous Other (JS Lib)
Browser Subsystems • Rendering • Layout • Block Building • Formatting • DOM • Marshalling • JavaScript • Collections • CSS • HTML • Networking
Browser Subsystems • Rendering • Layout Block Building Formatting DOM Marshalling • JavaScript Collections CSS HTML • Networking
Browser Subsystems Rendering Layout Block Building Formatting DOM Marshalling JavaScript Collections CSS HTML • Networking
Quick Caching Overview • First Request GET /images/banner.jpg HTTP/1.1 Host: www.microsoft.com • First Response HTTP/1.1 200 OK Content-Type: image/jpeg Expires: Fri, 30 Sep 2011 00:00:00 GMT • Second Request GET /images/banner.jpg HTTP/1.1 Host: www.microsoft.com No Response Required
Better performance, with the same markup! Caching Improvements • HTTP Caching Improvements • Improve heuristic expiration • Support: crazy-far-futures Expires headers • Support: Vary: Accept-Encoding • Support Vary: Host • Improved scavenger • Redirect caching • Back/forward optimization • Cross-domain HTTPS revalidation mitigation • Parallel Connection Improvements • Increase connections-per-proxy to 12 • Speculatively pre-open additional connection • Improved LCIE connection limiting • DNS Improvements • Pre-fetch based on Link Rel=Prefetch • Pre-fetch based on likely matches in ULV flyout • Pre-fetch addresses based on previous use • Fast-path for IP literals • General Improvements • Shorter User Agent String • Gracefully handle codepage restarts • Autoproxy in the frame • Imgsrc=”” shouldn’t send a request • Issue requests on the wire earlier • Only download requires files (fonts)
Network Optimizations Best Practices
Minify Your JavaScript Minified JavaScript e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('y v(){a=[];b.e=\'\';9 c=1;9 i=D/2-.5;d(9 x=-i;x<=i;x++){d(9 z=-i;z<=i;z++){9 0=l.H(\'0\');0.o("n","p");0.q.s=\'r\';0.m=x;0.f=z;g(h==k){j(c){8 1:0.6=t;c++;7;8 2:0.6=F;c++;7;8 3:0.6=G;c++;7;8 4:0.6=J;c++;7;8 5:0.6=w;c=1;7}}C{0.6=I}b.B(0);a.A(0)}}E.e=a.u}') function CreateBoard() { images = []; board.innerHTML = ''; var c = 1; var i = count / 2 - .5; for (var x = -i; x <= i; x++) { for (var z = -i; z <= i; z++) { varimg = document.createElement('img'); img.setAttribute("name", "rotatingimage"); img.style.left = '5000px'; img.x3d = x; img.z3d = z; if (useBrowserLogos == true) { switch (c) { case 1: img.src = IEIMAGE; c ++; break; case 2: img.src = LOGO2; c ++; break; case 3: img.src = LOGO1; c ++; break; case 4: img.src = LOGO4; c ++; break; case 5: img.src = LOGO3; c = 1; break; } } else { img.src = IMAGE; } board.appendChild(img); images.push(img); } } countimages.innerHTML = images.length; }
Reduce Network Connections <html> <head> <title>Test</title> </head> <body> … <imgsrc="a.gif" /> Item 1 <imgsrc="b.gif" /> Item 2 <imgsrc=“c.gif" /> Item 3 <imgsrc=“d.gif" /> Item 4 <imgsrc=“e.gif" /> Item 5 <imgsrc=“f.gif" /> Item 6 … </body> </html> <imgsrc="a.gif" /> Item 1 <imgsrc="b.gif" /> Item 2 <imgsrc=“c.gif" /> Item 3 <imgsrc=“d.gif" /> Item 4 <imgsrc=“e.gif" /> Item 5 <imgsrc=“f.gif" /> Item 6
Reduce Network Connections Use Image Sprites
Reduce Network Connections <head> <title>Test</title> <style type="text/css"> .a, .b { width: 10; height: 10 } .a, .b { background-image: "abc.gif" } .a { background-position: 0 0 } .b { background-position: 0 -10 } </style> </head> <body> … <div class="a"></div> Item 1 <div class="b"></div> Item 2 … </body> .a, .b { width: 10; height: 10 } .a, .b { background-image: "abc.gif" } .a { background-position: 0 0 } .b { background-position: 0 -10 } <div class="a"></div> <div class="b"></div>
Browser Subsystems Rendering Layout Block Building Formatting DOM Marshalling • JavaScript Collections CSS HTML Networking
The JavaScript Engine Foreground Source Code Parser AST ByteCode Interpreter
New JavaScript Engine – “Chakra” Foreground Source Code Parser AST ByteCode Interpreter Background Compiler Native Code Background Compiled JavaScript In The Background Using Multiple Cores
WebKitSunSpider JavaScript Benchmark Results Version 0.9.1, Results Generated September 4th, 2010
Better performance, with the same markup! New JavaScript Engine – “Chakra” Foreground Source Code Parser AST ByteCode Interpreter Background Compiler Native Code Background Compiled JavaScript In The Background Using Multiple Cores
JavaScript Best Practices
Minimize Symbol Resolution • var foo • obj.foo Global DOM Intermediate Scopes Prototype Chain Cost Local Instance
Minimize Symbol Resolution function WorkOnLocalVariable() { localVariable = 5; return ( localVariable + 1 ); } localVariable localVariable
Minimize Symbol Resolution function WorkOnLocalVariable2() { varlocalVariable = 5; return ( localVariable + 1 ); } varlocalVariable localVariable
Minimize Symbol Resolution function IterateWorkOverCollection2() { varfuncWork = Work; var length = myCollection.length; for(var i = 0; i < length; i++) { funcWork(myCollection[i]); } } varfuncWork = Work; funcWork
Reduce and Remove Duplicate Scripts <html> <head> <title>Test</title> </head> <body> … … <script src=“jquery.js” … ></script> <script src=“prototype.js” … ></script> <script src=“dojo.js” … ></script> <script src=“animater.js” … ></script> <script src=“extjs.js” … ></script> <script src=“yahooui.js” … ></script> <script src=“mochikit.js” … ></script> <script src=“lightbox.js” … ></script> <script src=“jslibs.js” … ></script> <script src=“yahooui.js” … ></script> • <script src=“yahooui.js” … ></script> • <script src=“yahooui.js” … ></script>
Browser Subsystems Rendering • Layout • Block Building • Formatting • DOM • Marshalling • JavaScript • Collections • CSS • HTML Networking
Windows Experience Index Results - GPU 15% 32% 27% 10% 4% 12% 1 2 3 4 5 6 7 8 Windows Experience Index Graphics Scores of Vista and Win7 Users