Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of the script.aculo.us user interface JavaScript library, a member of the Prototype core team and a Ruby on Rails core alumnus. You're using my work every day, even if you're not aware of it (sounds creepy, I know!). Need JS foo? Hire me.

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.

View more documents from Thomas Fuchs.

There’s benchmarks for the four most common JavaScript engines, SpiderMonkey (Firefox 3.5), JavaScriptCore (Safari 4), JScript (Internet Explorer 8) 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.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Facebook Share on Facebook

11 comments »

JavaScript Rocks! Peformance ebook
Do you run a web site or web application? Do your users a favor, and grab our ebook on JavaScript performance. Profit from our knowledge gathered in over 15 years of working with the Web and JavaScript and make your sites ultra-fast and your users ultra-happy.

11 Comments on “6 easy things you can do to improve your JavaScript runtime performance”

  1. 1 Mathieu said at 5:53 pm on November 8th, 2009:

    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!

  2. 2 Thomas Fuchs said at 5:59 pm on November 8th, 2009:

    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.

  3. 3 Daniel Kurdoghlian said at 9:03 pm on November 8th, 2009:

    Super Artikel – Dankeschön!
    War sehr informativ und hilfreich!

    kleine Anmerkung – aus dem IE8 [ 8) ] ist ein smiley geworden ;)

  4. 4 Radoslav Stankov said at 9:13 pm on November 8th, 2009:

    Very informative, one of the first things on Monday morning is to spread it though colleagues at work :) 10x

  5. 5 Nikola Klaric said at 4:45 pm on November 9th, 2009:

    This should be even faster: str | 0

    ~~+”12.5″ == 12
    “12.5″ | 0 == 12
    ~~+”abc” == 0
    “abc” | 0 == 0

    QED

    ;-)

  6. 6 Rhett Anderson said at 6:53 pm on November 9th, 2009:

    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.

  7. 7 Rhett Anderson said at 6:55 pm on November 9th, 2009:

    Does anyone have a short way to turn “3px” into 3 or “3″ (and “30px” into 30 or “30″)?

  8. 8 Steven said at 10:47 pm on November 9th, 2009:

    parseInt(“3px”) // gives 3

  9. 9 Sebastien Grosjean said at 11:32 pm on November 15th, 2009:

    Thanks a lot for showing off this performance tests, really helpful and time savers.

  10. 10 Evgeniy Dolzhenko said at 11:58 am on November 22nd, 2009:

    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

  11. 11 General JavaScript tips/tricks « Pat IT Dude Blog said at 12:28 pm on December 7th, 2009:

    [...] Best way to load your JavaScript Fast by Default and Web Performances 6 ideas to improve JavaScript performance Slow [...]


Leave a Reply