6 easy things you can do to improve your JavaScript runtime performance
November 8th, 2009 by Thomas Fuchs, 11 comments »Here are the slides from my “Extreme JavaScript Performance” talk that I gave at JSConf.eu on November 7 in Berlin.
I’m talking about 6 easy things you can do to improve your JavaScript runtime performance, ranging from simple things (function inlining) to some quite surprising findings on how JavaScript engines deal with loops.
There’s benchmarks for the four most common JavaScript engines, SpiderMonkey (Firefox 3.5), JavaScriptCore (Safari 4), JScript (Internet Explorer
and V8 (Google Chrome).
Be cautious however! Only do these optimizations if you have to, and, please, for the love of all the JavaScript gods, do not, ever, optimize prematurely.
Finally, here’s a PDF (750k) of the slides, if you want to read it offline and/or in dead tree form, and there’s a Github Gist of the example code, so you can run it yourself.
I welcome any comments, and findings you might have had with optimizing your JavaScript code.
Tweet This Post
Digg This Post
Share on Facebook









Great presentation, so instructive! It is scary to think about a JavaScript community without you and John Resig, you guys do so much. Thanks for everything Thomas!
Here’s a little update to the “string to integer coercion” part of the presentation:
You can also do: ~~+”12.5″ to coerce the string into an integer number.
Super Artikel – Dankeschön!
War sehr informativ und hilfreich!
kleine Anmerkung – aus dem IE8 [
] ist ein smiley geworden
Very informative, one of the first things on Monday morning is to spread it though colleagues at work
10x
This should be even faster: str | 0
~~+”12.5″ == 12
“12.5″ | 0 == 12
~~+”abc” == 0
“abc” | 0 == 0
QED
And you don’t need the unary plus at all, really.
~~”12.5″
“12.5″|0
Note that these replacements for floor work right only on positive numbers. But that’s OK for many applications.
Does anyone have a short way to turn “3px” into 3 or “3″ (and “30px” into 30 or “30″)?
parseInt(“3px”) // gives 3
Thanks a lot for showing off this performance tests, really helpful and time savers.
I believe the WTF with IE slow script alert could be explained by the following quote:
“Because the Internet Explorer 4.0, 5.0, 6, and 7 time-out is based on the number of script statements executed, the time-out dialog box will not display during ActiveX control or database-access delays. Endless loops in script will still be detected.”
http://support.microsoft.com/kb/175500
[...] Best way to load your JavaScript Fast by Default and Web Performances 6 ideas to improve JavaScript performance Slow [...]