JavaScript Performance : V8, Tracemonkey, SquirrelFish, IE8

     A few days ago, the Google announced a beta version of their web browser, called “Chrome”. 

     It has an interesting name, because the word, “Chrome”, is also used for the XML based GUI representation for the Firefox. Anyway, it looks to me that the Chrome, the Google’s web browser, is targeted for Web applications. As you know Web application is very important nowadays for enterprise market, because you don’t need to worry about what platform you must use. Whatever they are, they can share and use the same intranet infrastructure and in-house software if they are Web apps. Thanks to the Google Docs and the Google map, AJAX showed its edge on performance and also its flexibility in designing Web interface. So, current Web apps look like and behave like desktop apps. Will it mean the dead of desktop apps? Hmm.. I don’t know. But anyway let’s keep focused. In this post, I would like to talk about JavaScript performance of the various web browsers.

    Not long time ago, every others were beaten by the IE’s JavaScript performance, not by great margin, but sufficiently big margin. At that time they were interpreter, or VM based implementation. Sure, the JavaScript is a script language. So, it is reasonable approach. And due to the faster CPUs, the Web apps become more visible and started spreading widely. 

    So, I guess people started wanting more from their Web apps. And there are two strong contenders.

One is the TraceMonkey from the Mozilla and the other is the SquirrelFish from the WebKit. (For people who don’t know what is the WebKit, try thinking the Safari or the KHTML. )

     According to the TraceMonkey’s introduction page, native compilation is added to the JavaScript engine, and it uses a technique called “trace tree” from the UC Irvine. As you can see it from their page, linked above, it will be faster in the end, because they have plan to use SSE and Altivec. You can see that how fast it is compared to its predecessor.

TraceMonkey performance enhancement

(Click the image to read the full article)

    On the other hand, the SquirrelFish from the WebKit adopted bytecode compilation and technique similar to the “trace tree”. (Same link to the above link for the WebKit. ) You can see how fast it is compared to is predecessor from this picture.

 

SquirrelFish performance enhancement

SquirrelFish performance enhancement

     Or you can see a graph claimed by the Apple Inc here. But it is not for the SquirrelFish. The SquirrelFish is much faster JavaScript engine than the one used for the currently announced Safari browser.

 

Safari vs. IE and other on JavaScript performance

Safari vs. IE and other on JavaScript performance

     I did NOT read the paper on the “trace tree”, so I’m not sure how much different the techniques used for the SquirrelFish and the TraceMonkey. If anyone read it and compared them, please post what the differences are.

     Now, it is time for the Chrome’s V8.

According to its introduction page, it compiles the JavaScript source code and thus makes a native code. Let’s take excerpt from the page.

V8 compiles JavaScript source code directly into machine code when it is first executed. There are no intermediate byte codes, no interpreter. Property access is handled by inline cache code that may be patched with other machine instructions as V8 executes.

So, unlike the SquirrelFish, it is compiled to the native code. Therefore it should be faster than the SquirrelFish. It also uses other technique : Fast Property Access, Efficient Garbage Collection

How fast is the V8? Let’s take a look at it.

Performance Comparison

Performance Comparison

(The unit is in ms. So, the shorter is better)

Chrome test

Performance Comparison

 ( The longer is better )

 

Performance Comparison

Performance Comparison

( The unit is in ms. So the shorter is better. )

For more detailed explanation, please visit Wayne Pan’s blog.

What is interesting here is that Wayne used FireFox 3.1 Nightly [1.9.1b1pre/200809020331. According to his test, the V8 is faster. But in a mozillazine’s blog, it says the other way.

 

Is the TraceMonkey faster than the V8?

Is the TraceMonkey faster than the V8?

But even at the MozillaZine’s blog, it points out the cases which is slower than the V8.

 

TV vs. V8

TV vs. V8

 

According to this article, the Mozilla will be 7x faster in the end.

     So, they share something common that they are not based on interpreters anymore. VM can be thought as a better interpreter, but…. anyway.. Especially the TraceMonkey, i.e. TM, shares lots of things with the SquirrelFish. 

     Many of you will think that the TraceMonkey and the V8 are in native code, while the SquirrelFish is in bytecode, so the SquirrelFish is slower. Well.. yeah.. I think so. But probably the SquirrelFish can be faster in the long run. I guess there is reason Apple inc chose the SquirrelFish. In the next version of the Mac OS X, so called the Snow Leopard, more dynamic execution of code will be incorporated, called “Grand Central”. Also, to enhance security in the code and to adapt the performance more to specific cases, the execution of the binary code will be dynamically changed. For example, if clause’s execution path can be different under different cases, even though the whole if.. else.. block is same. So, implementing it in bytecode can have more potential in dynamical executed environment. So, we can’t conclude which approach is better yet.

(How about the Linux? Will it have similar technology like the Grand Central? )

     By the way, don’t forget that you can use the WebKit as a HTML engine while you can choose the SquirrelFish or the V8, as the Google does for its Chrome browser. ( Yeah.. in your code, you can use the WebKit, SquirrelFish and the V8 in your codes! )

     Currently, the Google advertised the Chrome more well than the Mozilla Firefox 3 and the WebKit. So, people are amazed by the Chrome performance, although they use very similar techniques and its performance is similar to those of others. This is the power of marketing or using journalism!

4 responses to this post.

  1. […] to compiles the JavaScript source code and makes it native code. (SquirrelFish is in bytecode). According to the preliminary benchmark, it could be ten-fold faster than before […]

    Reply

  2. […] 19 09 2008 As I summarized before, there are 3 strong players in the JavaScript engine field. Due to the Google’s chrome, how […]

    Reply

  3. […] JavaScript Performance : V8, Tracemonkey, SquirrelFish, IE8 […]

    Reply

  4. […] JavaScript Performance : V8, Tracemonkey, SquirrelFish, IE8 Passende Beiträge in der Blogosphäre zu TraceMonkey SquirrelFish Extreme: Fastest JavaScript Engine Yet […]

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: