Javascript gets new lease of life

ctodx
22 September 2008

Over the past week or so, I've been using the new Chrome browser from Google -- not because I happen to be a geek fashionista and have to have all the latest gadgets, but to check out its JavaScript interpreter performance with real-world applications, including our own ASP.NET controls.

You may not have noticed but in the arcane world of JavaScript interpreters there has been some remarkable changes in the last few months. In essence, JavaScript interpreters have been gaining just-in-time compiler features, or JITters, just like we have in .NET.

This, to me, or indeed to anyone who has dabbled in JavaScript, is nothing short of amazing. JavaScript is a dynamic, weakly-typed, interpreted (or scripting) language with some very strong functional language features, despite its name implying Java and hence being statically-typed and imperative. The thought that this "freeform" quality can be compiled, and not only that but compiled just in time, seems contradictory and reeking of magic.

Luckily, not everyone is as gobsmacked as me, and they have been working hard to improve the performance of interpreting and executing JavaScript code. After all, most of the Web 2.0 sites out there are heavily using some form of AJAX, where the "J" stands for JavaScript, so a simple way to improve everyone's website performance is to improve the execution of the code.

There have been quite a few developments in the JavaScript interpreter space:

  • TraceMonkey: this is the new JITter/interpreter for the upcoming Firefox 3.1. Firefox 3.0 and earlier use an engine called SpiderMonkey. (In essence, TraceMonkey is SpiderMonkey plus tracing of the code so that sub-method blocks can be nanoJiTted.)
  • V8: the new JavaScript engine in Google Chrome.
  • SquirrelFish: the JavaScript interpreter for Safari 4.0, used in WebKit, the underlying HTML renderer in Apple Safari. (Confusingly, Google Chrome uses WebKit for rendering, but V8 for JavaScript code execution.)
  • Futhark: the engine for Opera 9.5 or later.

The interesting thing about these new interpreters is that they all blow IE's interpreters out of the water. And that includes IE8 beta, as well as IE7. It's becoming clear that if you want superior JavaScript performance for your web apps, you need to specify ABIE (Anything But Internet Explorer).

Currently there are two main JavaScript execution benchmarks: SunSpider (WebKit's benchmark for pure JavaScript, that is, no DOM processing), and the Google Chrome benchmark (again for pure JavaScript with no DOM). The difference between them is that the Chrome benchmark is very recursion intensive, something that TraceMonkey cannot do well at this stage. In Google's defense, using the DOM for anything intensive is going to be very recursion-oriented. (There is a new benchmark being developed that mixes in DOM processing as well, Dromaeo, but it's in its early days yet.) All the beta JIT engines perform extreemly well with these benchmarks, with V8 doing best at Google's own benchmark. IE is a no-show in some of the results since its interpreter has a tendency to crash with some benchmarks.

I do note that the fastest JavaScript interpreters/JITters are still in beta, but the whole area certainly looks very promising. I must admit that I hope the JavaScript execution engines become standalone, so that you can use your favorite browser and plug-in the engine you prefer. Perhaps a vain hope, but a hope nevertheless.

As for Chrome, and speaking as a user, it certainly seems to be very responsive on AJAX-abundant websites, including our own website, demo pages, and community site. The rendering speed is excellent too.

I look forward to yet more improvements in JavaScript performance. Certainly, as Scott Hanselman acknowledged, Silverlight may not yet have the upper hand yet in web applications.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.