Thanks to a number of updates to the TraceMonkey JavaScript engine

Jan 14, 2010 14:53 GMT  ·  By
Thanks to a number of updates to the TraceMonkey JavaScript engine, Firefox 3.6 is now significantly faster
   Thanks to a number of updates to the TraceMonkey JavaScript engine, Firefox 3.6 is now significantly faster

JavaScript performance has become the megahertz war of web browsers and each vendor is trying to one up the other in this area. This can be largely attributed to Google's quest for improved web app performance, which it pursued with its own Chrome web browser. When Google Chrome came out, it left all other browsers in the dust and since then it has only become faster. Mozilla has been making strides too with Firefox trying to catch up and is moving even further with the upcoming Firefox 3.6 release.

"Firefox 3.5 introduced TraceMonkey, our new JavaScript engine that traces loops and JIT compiles them to native (x86/ARM) code. Many JavaScript programs ran 3-4x faster in TraceMonkey compared to Firefox 3," writes David Mandelin, a software engineer working on Mozilla's JavaScript team. "For JavaScript performance in Firefox 3.6, we focused on the areas that we thought needed further improvement the most."

There are two main areas on which Mozilla focused with Firefox 3.6. First, there was the need to expand the number of cases where TraceMonkey was used as not all JavaScript code was ran through the native code compiler. JavaScript used by Firefox itself in the UI elements wasn't optimized and neither were add-ons using JavaScript.

TraceMonkey wasn't mature enough when Firefox 3.5 came out so the team decided to skip it for the interface mostly for security reasons. UI JavaScript code has greater privileges than content JavaScript and, as such, can be more dangerous if something goes wrong. Mozilla says that the performance improvements from this move shouldn't be too noticeable in the browser's UI as it was already heavily optimized. However, add-ons which make heavy use of JavaScript should get a considerable speed bump.

The second big improvement comes updated to the Garbage Collector (GC) Firefox uses to clean up JavaScript memory. Previously, the GC would pause all running JavaScript code as it freed up the memory. This caused small but sometimes noticeable pauses which were especially visible in animations. With Firefox 3.6, the GC was relegated to a separate processing thread, meaning that the main thread was left to do all the JavaScript processing uninterrupted. Mozilla says that those running multi-core processors will see the biggest gains, but it should be faster even on single core processors.

Another major improvement was making the GC aware of the native code compiled by TraceMonkey. Previously, the native code cache would be flushed along with the unused memory, meaning that every time the GC ran code had to be re-compiled. This doesn't happen anymore leading to less 'freezes' and pauses and smoother animations. The post on Mozilla's Hacks blog lists several other smaller improvements to the JavaScript engine in greater detail.

If you want to check out the speed improvements for yourself, Firefox 3.6 RC1 (Release Candidate) for Windows is available for download here. Firefox 3.6 RC1 (Release Candidate) for Mac OS X is available for download here. Firefox 3.6 RC1 (Release Candidate) for Linux is available for download here.