docs/compiler/sparkplug/compiler-sparkplug.md
Sparkplug is V8's baseline compiler, introduced to fill the performance gap between the Ignition interpreter and the highly-optimizing TurboFan compiler.
While V8's Ignition interpreter is highly optimized, interpreters have inherent overheads such as bytecode decoding and dispatch. On the other hand, the TurboFan optimizing compiler can generate highly optimized code, but it requires time to run and needs stable type feedback to be effective.
Sparkplug fills this gap by providing a fast compiler that generates machine code quickly, allowing for aggressive tier-up without waiting for stable feedback.
Sparkplug is a non-optimizing compiler that compiles Ignition bytecode directly into machine code.
The BaselineCompiler (defined in src/baseline/baseline-compiler.h) drives the compilation:
BytecodeArray using a BytecodeArrayIterator.VisitAdd, VisitStar).BaselineAssembler to emit the corresponding machine code instructions.Sparkplug maintains stack frames that are compatible with the Ignition interpreter. This design choice simplifies many aspects of integrating a new compiler:
FeedbackCell for the currently executing function. (The FeedbackVector is also available in the frame, as in interpreter frames).Sparkplug actually generates very little of its own code for complex operations. JavaScript semantics are complex, and regenerating this code inline would increase compile times and memory consumption.
Instead, Sparkplug code mostly calls into "builtins" (small snippets of machine code embedded in the binary) to do the work. These builtins are often the same ones used by the interpreter or share most of their code with the interpreter's bytecode handlers. Sparkplug code is essentially a sequence of builtin calls and control flow.
src/baseline/: Core Sparkplug implementation.src/baseline/baseline-compiler.cc: Contains the main compiler loop and bytecode visitors.src/baseline/baseline-assembler.h: Provides an abstraction over the macro-assembler for Sparkplug.