marzelin
marzelin

Reputation: 11600

What does V8's ignition really do?

On https://v8.dev/docs/ignition we can see that:

Ignition is a fast low-level register-based interpreter written using the backend of TurboFan

on https://docs.google.com/document/d/11T2CRex9hXxoJwbYqVQ32yIPMh0uouUZLdyrtmMoL44/edit?ts=56f27d9d#

The aim of the Ignition project is to build an interpreter for V8 which executes a low-level bytecode, thus enabling run-once or non-hot code to be stored more compactly in bytecode form.

The interpreter itself consists of a set of bytecode handler code snippets, each of which handles a specific bytecode and dispatches to the handler for the next bytecode. These bytecode handlers

To compile a function to bytecode, the JavaScript code is parsed to generate its AST (Abstract Syntax Tree). The BytecodeGenerator walks this AST and generates bytecode for each of the AST nodes as appropriate.

Once the graph for a bytecode handler is produced it is passed through a simplified version of Turbofan’s pipeline and assigned to the corresponding entry in the interpreter table.

So it seems that Ignition job is to take bytecode generated by BytecodeGenerator convert it to bytecode handlers and execute it through Turbofan.

But here: enter image description here

and here: enter image description here

You can see that it is ignition that produces bytecode.

What is more, in this video https://youtu.be/p-iiEDtpy6I?t=722 Ignition is said to be a baseline compiler.

So what's it? A baseline compiler? A bytecode interpreter? An AST to bytecode transformer?

This image seems to be most appropriate: enter image description here

where ignition is just an interpreter and everything before is no-name bytecode generator/optimizer thing.

enter image description here

Upvotes: 9

Views: 4004

Answers (4)

Ernest Yoyowah
Ernest Yoyowah

Reputation: 1

What V8's Ignition Does

V8’s Ignition is responsible for converting the Abstract Syntax Tree (AST) of JavaScript code into bytecode. But instead of compiling the entire code to machine code right away, Ignition first creates a compact intermediate representation (bytecode). This helps speed up the initial execution of code, enabling the program to start running faster.

  • Bytecode Generation: Ignition takes the parsed JavaScript (represented as an AST) and translates it into bytecode, a simpler form that's quick to interpret and execute. This allows the engine to avoid the delays of full compilation at the start.

  • Efficient Interpretation: The bytecode generated by Ignition is not directly machine code, but it’s much more efficient to execute than raw JavaScript. This enables fast initial execution while allowing the V8 engine to keep working on optimizing performance in the background.

  • Fast Startup: Ignition’s role is to make sure JavaScript code can be executed quickly after being parsed, without having to wait for the full JIT compilation to be done. This results in faster startup times, especially for smaller code snippets.


In short, Ignition helps V8 process JavaScript code efficiently at runtime by first converting it into bytecode, ensuring that code can start running quickly while still leaving room for optimization later on with TurboFan.

Upvotes: 0

Amir
Amir

Reputation: 2470

Please correct my mistake in understanding the conversion process:

  • JS code parsed into AST
  • AST sent to Ignition to be converted into bytecode
  • Generate Machine Code
  • If byte code is optimal, Send it to the CPU for processing
  • If byte code needs optimization, it is sent to Turbofan for optimization
  • If Turbofan received byte code, it further optimizes, and sent to computer for processing.

Upvotes: -1

T.J. Crowder
T.J. Crowder

Reputation: 1073959

As I mentioned in a comment, sadly some of the docs are out of date, including the one with your first graphic above. Full-codegen and Crankshaft are no longer used at all, it's purely parsing and Ignition + TurboFan. (you've removed the image from the outdated docs that sadly are still linked by some of the V8 docs)

Ignition is a high-speed bytecode interpreter.

V8's parser produces Ignition bytecode. That bytecode is executed (interpreted) by Ignition. Code that only runs once (startup code and such) or isn't run often stays at the bytecode level and continues to be executed by Ignition.

"Hot" code goes to the second phase, where TurboFan kicks in: TurboFan's input is the same bytecode that Ignition interprets (rather than source code, as it was with Crankshaft), which it then aggressively compiles to highly-optimized machine code that runs directly (rather than being interpreted).

This article goes into the motivations for moving off Full-codegen and Crankshaft (memory savings in the former case, difficulty implementing and in particular optimizing language features in the second). The design of TurboFan also helps the V8 authors minimize the amount of platform-specific code they have to write (by having an intermediate representation, which amongst other things they can also use to write Ignition's bytecode handlers).

Upvotes: 6

jmrk
jmrk

Reputation: 40491

V8 developer here.

On https://v8.dev/docs/ignition we can see that:

Ignition is a fast low-level register-based interpreter written using the backend of TurboFan

Yes, that sums it up. To add a little more detail:

  • The name "Ignition" refers to both the Bytecode Generator and the Bytecode Interpreter. Often, the entire thing is also seen as one big black box and casually called "the interpreter", which can sometimes lead to a bit of confusion around the terms.
  • The Bytecode Generator takes the AST produced by the Parser for a given JavaScript function, and generates bytecode from it.
  • The Bytecode Interpreter takes the bytecode generated by the Bytecode Generator and executes it by interpreting it by sending it to a set of Bytecode Handlers.
  • The Bytecode Handlers that make up the Bytecode Interpreter are generated using parts of the Turbofan pipeline. This happens at V8 compilation time, not at runtime. In other words, you need Turbofan to build (parts of) Ignition, but not to run Ignition.
  • The Parser (and the AST/Abstract Syntax Tree it produces are not part of Ignition.

Once the graph for a bytecode handler is produced it is passed through a simplified version of Turbofan’s pipeline and assigned to the corresponding entry in the interpreter table.

So it seems that Ignition job is to take bytecode generated by BytecodeGenerator convert it to bytecode handlers and execute it through Turbofan

This section of the design document talks about generating the Bytecode Handlers, which happens "ahead of time" (i.e. when V8 is compiled) using parts of Turbofan. At runtime, bytecode is not converted to handlers, it is "handled" (=run, executed, interpreted) by the existing fixed set of handlers, and Turbofan is not involved.

What is more, in this video https://youtu.be/p-iiEDtpy6I?t=722 Ignition is said to be a baseline compiler.

At that moment, the talk is referring to the general idea that all modern JavaScript engines have a "baseline compiler" (in a very general, conceptual sense -- I agree that the slide could have made that clearer). Note that the slide does not say anything about Ignition. The next slide says that Ignition fills that role in V8. So more accurate would be to say "Ignition takes the place of a baseline compiler" or "Ignition is a baseline execution engine". Or you could redefine your terms slightly and say "Ignition is a compiler that produces bytecode and then interprets it".

ignition is just an interpreter and everything before is no-name bytecode generator/optimizer thing

That slide shows the "Interpreter" box as part of the "Ignition Bytecode Pipeline". The Bytecode Generator/Optimizer are also part of Ignition.

Upvotes: 15

Related Questions