BT

Facilitating the spread of knowledge and innovation in professional software development

Contribute

Topics

Choose your language

InfoQ Homepage News V8 Gets a Non-Optimizing Compiler Stage to Improve Performance

V8 Gets a Non-Optimizing Compiler Stage to Improve Performance

This item in japanese

Bookmarks

The latest version of the JavaScript V8 engine, V8 9.1, introduces a new intermediate compiler stage, called Sparkplug, that improves performance on real-world benchmarks by 5-15%, says V8 engineer Leszek Swirski. It will be available in the upcoming Chrome 91.

The old V8 architecture included just two stages: Ignition, a JavaScript interpreter, and TurboFan, a highly optimising compiler. Ignition takes a JavaScript AST and generates V8 bytecode, while TurboFan is able to generate machine code from that. The reason for the introduction of Sparkplug is clearly explained in the Sparkplug design overview:

There is a big performance cliff between [Ignition and TurboFan]; staying too long in the interpreter means we don’t take advantage of optimisation, but calling TurboFan too early might mean we “waste” time optimising functions that aren’t actually hot — or worse, it means we deopt. We can reduce this gap with a simple, fast, non-optimising compiler, that can quickly and cheaply tier-up from the interpreter by linearly walking the bytecode and spitting out machine code. We call this compiler Sparkplug.

Before the introduction of Ignition and TurboFan, V8 used to have a fast JIT compiler called Full-CodeGen (FCG). As Leszek explains in a Hacker News thread, this was ditched in favour of a new interpreter architecture, called Ignition, which did not include FCG.

The big difference is that Sparkplug compiles from bytecode, not from source, and thus the bytecode stays the source of truth for the program. Back in the FCG days, the optimising compiler had to re-parse the source code to AST, and compile from there - even worse, to be able to deoptimise back to FCG, it had to kind of "replay" FCG compilation to get the deopted stack frame right.

Leszek mentions that FCG was ditched instead of evolved because of its massive technical debt, specifically related to the fact that both the Ignition compiler and FCG had to compile from source and provide their output to TurboFan, which led to all kind of complexities. This also made it harder to keep up with JavaScript new features.

Sparkplug speed comes from two factors, says Swirski. First, it relies on bytecode generated by Ignition, which means a bunch of work has already been done, including variable resolution, figuring out if parentheses are actually arrow functions, desugaring destructuring statements, and so on. Additionally, Sparkplug does not generate any intermediate representation (IR), rather it outputs machine code in a single linear pass. This approach means Sparkplug cannot do any advanced optimizations based on IR and it must be entirely ported to each new platform.

When it comes to performance, Sparkplug improves both the Speedometer as well as a set of real-world benchmarks used by the V8 team. The improvement is in the range of 5-15% depending of test machine and website. Google has not released official low-level benchmarks comparing the various pipeline components' performance. Leszek, though, explains that:

Compile time is on roughly the same order of magnitude as Ignition compilation (just AST to bytecode, so excluding parsing), and roughly two to three orders of magnitude faster that TurboFan. The relative performance to the interpreter, as the sibling comments point out, varies wildly by workload, but around 4x is probably a decent approximation for something not entirely dominated by property loads.

Besides performance, another key benefit of Sparkplug is reduced CPU usage, which can improve battery usage on mobile devices as well as reduce the bill on pay-per-cycle servers, according to V8 designers.

As mentioned, Sparkplug is being currently rolled out in Chrome 91 so you will soon be able to try it out.  If you are interested in the nitty-gritty details of Sparkplug internals and the way it interfaces with Ignition and TurboFan, do not miss Swirski's writeup.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.