Google has announced that the latest beta for Chrome, their web browser, will compile Javascript in a background thread. In the current release version, scripts are converted to instructions, executed, monitored for performance, and swapped with a more optimized set of instructions that accomplishes the same tasks. Converting script into optimized instructions takes time. Doing it on a background thread frees up that computation time for something else.

This stutter was 628 milliseconds, or about 38 consecutive frames at 60 FPS.

Image Credit: Chromium Project Blog

Web browsers are designed under the assumption that a single thread of instructions will weave through every task, one by one, until everything is done. At some point, since the early 1990s, computers have been give multiple cores (and some of those designs can have multiple threads shoved through at once). The problem is now that, since "Task A" was designed to occur before "Task B", doing them separately… can break stuff good.

A simplified browser execution flowchart. Execution follows the arrow.

Image Credit: Mozilla

Background Javascript optimization will be most effective for mobile SoCs. These processors tend to have a lot of fairly slow cores; the exact opposite of what a web browser wants. Also, video games have many tasks which occur every frame. Freeing up time on the main thread gives these apps more time to be more complex – and with less stutter (if optimizing blocks execution… which it is trying to optimize). This might also allow browsers more time to try more aggressive optimization strategies.

In case you are wondering, Mozilla started to move compilation to a background thread as of Firefox 21. Firefox 29 will move the entire just-in-time (JIT) compilation process off the main thread. This is currently in their "Aurora" release channel. To the rest of the world: it's an alpha.

This optimization is currently available in Google Chrome Beta (33).