TNW Sites

Google speeds up Chrome by compiling JavaScript in the background

Google today revealed a tweak it has made in the latest Chrome beta to further boost performance: concurrent compilation, which offloads a large part of the optimizing compilation phase to a background thread. Previously, Chrome compiled JavaScript on the main thread, where it could interfere with the performance of the JavaScript application.

As a result, Google says JavaScript applications remain responsive and performance gets a boost. This is all handled by V8, Chrome’s JavaScript engine.

Here’s how it works. First, V8 defers compilation of JavaScript functions until immediately before they are executed the first time (to reduce the overall time spent compiling). Next, pieces of code that are executed very often are compiled a second time by a specialized optimizing compiler. This second pass makes takes more time, but thanks to many advanced optimization techniques, it delivers much faster code.

Here is Chrome without concurrent compilation (V8 is fully occupied optimizing a large piece of code, causing an execution pause):

Here is Chrome with concurrent compilation (V8 still optimizes the large piece of code, but does so in a background thread):

The graphs above show excerpts of V8’s vital signs when running Mandreel, part of Google’s Octane benchmark suite, on a Nexus 5. The black bar represents JavaScript execution, so the goal is to get it as close to solid as possible.

Instead of taking turns compiling optimized Javascript code and executing it, V8 now uses concurrent compilation for large pieces of code to avoid stuttering and dropped frames in complex applications like games. We can expect these improvements to arrive in the stable version of Chrome in the next few months.

Emil was a reporter for The Next Web between 2012 and 2014. Over the years, he has covered the tech industry for multiple publications, including Ars Technica, Neowin, TechSpot, ZDNet, and CNET. Stay in touch via Facebook, Twitter, and Google+.