You serve up your code gzipped. Your caches are properly configured. Your data (and scripts) are loaded on-demand. That's awesome—so don't stop there. Runtime is another source of slowdowns, and you can learn to conquer those, too.
Learn how to benchmark your code to isolate performance issues, and what to do when you find them. The techniques you'll learn range from the normal (function inlining) to the extreme (unrolling loops).
Ana Mui Stanley, Self Employed at HomeJavascript gives me headeache, but your explanation seems understandable. I’m Ana Mui Stanley, working on my latest site on lyrics, www.lyrics-search.org/ . I enjoy reading the slide.2 years ago
Are you sure you want to
GeorgeSummerExcellent presentation, enjoyed it! Congrats for the presentation!
http://www.riding-mower.org/
http://www.riding-mower.org/la175-john-deere-lawn-tractor/2 years ago
Thomas Fuchs
@thomasfuchs
Extreme
JavaScript
Performance
DO NOT, EVER,
OPTIMIZE
PREMATURELY
http://tr.im/extremejs
SpiderMonkey
SpiderMonkey
JavaScriptCore
SpiderMonkey
JavaScriptCore
JScript
SpiderMonkey
JavaScriptCore
JScript
V8
#1
avoid function calls
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;
}
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;
}
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;
}
double bitwise NOT*
floors the number
> ~~(1 * "12.5")
12
1 * string coerces the
string into a float,
result = 12.5
*good overview on http://tr.im/bitwise
Firefox is 30x faster
than Safari
parseInt() weird stuff
0.003s 0.002s
0.088s 0.081s
uhm, hmm† 0.547s
0.109s 0.282s
#3
loops
var test = '';
for (var i = 0;i<10000;i++)
test = test + str;
var test = '', i = 10000;
while(i-‐-‐) test = test + str;
for loop while loop
0.12s 0.12s
0.13s 0.13s
0.6s 0.6s
0.04s 0.04s
for loop while loop
0.12s 0.12s
0.13s 0.13s
0.6s 0.6s
0.04s 0.04s
for loop while loop
0.12s 0.12s
0.13s 0.13s
0.6s 0.6s
0.04s 0.04s
for loop while loop
0.12s 0.12s
0.13s 0.13s
0.6s 0.6s
0.04s 0.04s
for loop while loop
0.12s 0.12s
0.13s 0.13s
0.6s 0.6s
0.04s 0.04s
3 expressions in “for”
var test = '';
for (var i = 0;i<10000;i++)
test = test + str;
var test = '', i = 10000;
while(i-‐-‐) test = test + str;
1 expression in “while”
(when i equals 0, expression will be false)
function normalLoop(){
var i=60, j=0;
while(i-‐-‐) j++;
}
function uncached(){
var i = 10000;
while(i-‐-‐) window.test = 'test';
}
function cached(){
var w = window, i = 10000;
while(i-‐-‐) w.test = 'test';
}
not a pure engine optimization,
the execution actually stops
here, n=2 needs to
be evaluated,
>>> var n = 1; so n is set to 2
undefined
>>> if(true && (n=2)) ...;
>>> n
2
>>> if(true || (n=3)) ...;
>>> n here it doesn’t
2 (expression must
be true), so n is
NOT set to 3
#6
what not to use
function(){
var obj = { prop: 'test', str: '' };
with(obj){
var i = 10000;
while(i-‐-‐) str += prop;
return str;
}
}
function(){
var obj = { prop: 'test', str: '' }, i = 10000;
while(i-‐-‐) obj.str += obj.prop;
return obj.str;
}
Thanks for sharing.
http://www.clickandsendparcel.com 1 year ago
http://www.riding-mower.org/
http://www.riding-mower.org/la175-john-deere-lawn-tractor/ 2 years ago
John.
www.freeringtones.ws/ 2 years ago