Google has introduced Sparkplug, a new compiler designed to improve JavaScript performance in Chrome, debuting with Chrome 91. Sparkplug is integrated into the V8 JavaScript/WebAssembly engine and aims to offer a faster, more efficient compilation process. Unlike traditional optimizing compilers, Sparkplug is described as a “super-fast” non-optimizing compiler, focused on delivering quick performance without the need for extensive optimizations. Positioned between the Ignition interpreter and the TurboFan optimizing compiler in the V8 pipeline, Sparkplug represents a novel approach to enhancing JavaScript execution speed.
What sets Sparkplug apart from other compilers is its method of compiling bytecode rather than directly compiling JavaScript source code. By working with bytecode that has already been processed by the bytecode compiler, Sparkplug avoids the overhead of repeating steps like variable resolution, determining whether parentheses are arrow functions, or desugaring destructuring statements. This streamlined process makes Sparkplug highly efficient, as it can generate machine code in a single pass, directly matching the bytecode’s execution without creating intermediate representations.
The entire Sparkplug compiler is designed as a simple switch statement within a for loop, which dispatches machine code generation functions. This minimalistic approach contributes to Sparkplug’s speed, as it eliminates unnecessary complexity, allowing for a faster compilation process compared to traditional methods. By compiling directly from bytecode to machine code in a single pass, Sparkplug aims to reduce latency and improve the overall responsiveness of JavaScript applications in Chrome.
Since 2016, Google’s V8 team has shifted focus away from synthetic benchmarks, such as Octane, in favor of measuring real-world performance. This change reflects the team’s commitment to improving JavaScript performance outside the confines of an optimizing compiler. As part of this broader effort, Google has worked on optimizing various components of V8, including the parser, streaming capabilities, object model, and caching of compiled code. With Sparkplug, the V8 engine continues to evolve, offering developers and users improved JavaScript performance in real-world scenarios.