• V8 Gets a non-optimizing Compiler Stage to Improve Performance
  • Sergio De Simone
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: CarlosChenN
  • Proofread: Chorer, PassionPenguin

V8 introduced a new non-optimized compiler to improve performance

The latest version of the JavaScript V8 engine, V8 9.1, introduces a transitional compilation phase called Sparkplug. According to V8 developer Leszek Swirski, it improves performance by 5-15% on real-world benchmarks. It will be available in the upcoming release of Chrome 91.

The old V8 architecture consisted of two phases: Ignition (a JavaScript interpreter), and TurboFan (a highly optimized compiler), Ignition uses JavaScript abstract syntax trees to generate V8 bytecodes, which TurboFan uses to generate machine code. The reasons for introducing Sparkplug are explained in detail in the Overview of the Sparkplug design.

There’s a huge performance difference between Ignition and TurboFan; Staying in the interpreter for too long meant we weren’t getting the benefits of optimization, but calling TurboFan too early meant we were optimizing functions that weren’t part of the hot code, or worse, it meant we were doing things we didn’t need to do. We can bridge this gap with a simple and fast non-optimized compiler that can be layered quickly and inexpensively from the interpreter by linearly iterating through the bytecode and spitting out the machine code. We call this compiler Sparkplug.

Before introducing Ignition and TurboFan, V8 used a fast just-in-time compiler called Full-CodeGen (FCG). As Leszek explains in Hacker News, the new interpreter architecture Ignition ditches this compiler and no longer includes FCG.

One big difference is that Sparkplug is compiled from bytecode, not source code, so bytecode is the true source of the program. Back in the DAYS of FCG, optimizing compilers had to reinterpret source code into abstract syntax trees and then compile from there, or even worse, can de-optimize to FCG, which had to be a bit like repeating FCG compilation to correct misselected stack frames.

Leszek mentioned that the reason FCG was abandoned rather than improved was because of its huge technical burden, particularly related to the Sparkplug compiler and FCG having to compile from source and then feed the output to TurboFan, which led to all sorts of complications. It also makes it harder for FCG to keep up with new features in JavaScript.

Sparkplug’s speed comes from two factors, Swirski said. First, it relies on bytecode generated by TurboFan, which means a lot of work has already been done, including variable parsing, determining whether parentheses are arrow functions, desugaring for deconstructed declarations, and more. In addition, Sparkplug does not generate any intermediates, but outputs machine code in a single linear channel. This approach means that Sparkplug cannot do any advanced optimizations based on intermediates, and it must be fully ported to each new platform.

In terms of performance, Sparkplug improves the Speedometer and a realistic set of benchmarks used by the V8 team. Performance improvements range from 5 to 15 percent, depending on the test machine and site. Google has not released official low-level benchmarks for the performance of various pipeline components. But Leszek explains here:

The compile time is about the same as the Ignition compiler (because it abstracts syntax tree to bytecode, not parsing), and about two or three orders of magnitude faster than TurboFan. As noted in the comments, the relative performance of the interpreter can vary greatly depending on the amount of work done, and in cases where attribute loads are not entirely controlled, about 4x is a good approximation.

In addition to performance, another key benefit of Sparkplug, according to V8’s designers, is reduced CPU usage, which in turn reduces the power consumption of mobile devices, as well as the cost of pay-per-cycle servers.

As mentioned, Sparkplug will be available in Chrome 91 so you’ll soon be able to try it out for yourself. If you’re interested in the kernel details of Sparkplug and its connection to Ignition and TurboFan. Then don’t miss The Swirski article.

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.