Turboshaft: Why V8 Left the Sea of Nodes for a Traditional CFG

By

V8's optimizing compiler Turbofan was one of the few production compilers using the Sea of Nodes (SoN) intermediate representation (IR). However, over the past three years, V8 has been transitioning to a more conventional Control-Flow Graph (CFG) IR called Turboshaft. This shift is now nearly complete: the JavaScript backend runs on Turboshaft, and WebAssembly uses it throughout its pipeline. Only a few remnants of SoN remain in the builtin pipeline and the frontend of the JavaScript pipeline, which are being replaced by Turboshaft and the Maglev CFG-based IR. This Q&A explores the reasons behind this significant architectural change.

1. What is the Sea of Nodes and why did V8 initially adopt it?

The Sea of Nodes (SoN) is an intermediate representation where operations (nodes) are not ordered into basic blocks or a control-flow graph. Instead, nodes float freely, connected by data dependencies and a separate control-flow dimension. V8 adopted SoN for its Turbofan compiler about 12 years ago as a successor to Crankshaft. The main advantage of SoN was its flexibility: it allowed optimizations like global value numbering and scheduling to be performed without being constrained by a fixed control-flow order. This was especially useful for handling complex operations and speculative optimizations in JavaScript. Turbofan was one of the first large-scale production compilers to use SoN, and it helped V8 achieve significant performance improvements for modern JavaScript applications.

Turboshaft: Why V8 Left the Sea of Nodes for a Traditional CFG
Source: v8.dev

2. What problems did Crankshaft have that led to the creation of Turbofan?

Crankshaft, V8's earlier optimizing compiler, suffered from several critical limitations:

These issues motivated the development of Turbofan with Sea of Nodes.

3. Why is V8 moving away from Sea of Nodes now?

Despite its strengths, Sea of Nodes introduced its own set of challenges. The exotic, non-linear representation made the compiler harder to understand, debug, and evolve. Many optimizations that are straightforward in a Control-Flow Graph (CFG) — like dead code elimination, register allocation, and precise scheduling — became complex and error-prone in SoN. Additionally, the JavaScript ecosystem evolved: engines now need to optimize for WebAssembly, which benefits from a more traditional CFG pipeline. The V8 team realized that a CFG-based IR like Turboshaft would simplify the compiler’s design while still delivering high performance. Turboshaft allows for easier introduction of new optimizations, better support for try-catch, and smoother integration with Maglev, a mid-tier CFG compiler. The transition was gradual to avoid regressions, but after three years, the benefits are clear: faster development cycles and more predictable performance.

4. What is Turboshaft and how does it differ from Sea of Nodes?

Turboshaft is a new intermediate representation (IR) based on a traditional Control-Flow Graph (CFG). Unlike Sea of Nodes, where nodes float freely and are connected by data and control edges, Turboshaft organizes operations into basic blocks arranged in a control-flow sequence. This makes the IR more familiar to compiler developers and easier to optimize using classic techniques like constant folding, dead code elimination, and instruction scheduling. Turboshaft also has better support for introducing control flow during lowerings, which is essential for handling type-specific operations and deoptimization paths. Another key difference is that Turboshaft integrates seamlessly with Maglev, a CFG-based mid-tier compiler, allowing a unified approach across optimization levels. The result is a simpler, more maintainable compiler that still achieves excellent performance—often matching or exceeding Turbofan. For WebAssembly, Turboshaft provides a clean pipeline from Bytecode to machine code without the overhead of SoN.

5. What parts of V8 still use Sea of Nodes and when will they be replaced?

As of now, only two parts of Turbofan still operate on Sea of Nodes: the builtin pipeline and the frontend of the JavaScript pipeline. The builtin pipeline handles internal V8 functions (builtins) that are often performance-critical. The frontend of the JavaScript pipeline is responsible for converting JavaScript code into the initial IR before optimization. V8 is actively replacing both with Turboshaft. Additionally, the frontend is being replaced by Maglev, a lightweight CFG-based compiler that handles tier-up from the interpreter. The builtin pipeline is being gradually migrated to Turboshaft as well. The V8 team expects these transitions to complete within the next year. Until then, Sea of Nodes remains in use for those specific paths, but it is no longer the primary IR for new feature development or optimizations.

6. How does this transition improve JavaScript and WebAssembly performance?

The move to Turboshaft eliminates many of the performance cliffs and deoptimization loops that plagued Crankshaft and also some issues in Turbofan. By using a CFG IR, Turboshaft can apply more precise analysis and optimization passes without the complexity overhead of Sea of Nodes. This leads to more stable and predictable performance across a wide range of JavaScript patterns. For example, try-catch blocks are now supported efficiently, and type-specific lowering is easier to implement. For WebAssembly, Turboshaft’s linear CFG allows straightforward mapping from WAT (WebAssembly Text Format) operations to machine code, reducing compilation time and enabling better instruction selection. Benchmarks have shown that Turboshaft matches or surpasses Turbofan’s peak performance while reducing compilation memory usage. Moreover, the simpler IR makes it easier for the V8 team to add new optimizations quickly, ensuring that JavaScript and WebAssembly continue to get faster with each Chrome release.

Tags:

Related Articles

Recommended

Discover More

The Man Behind the Moon: Anton Kiriwas and NASA's Artemis JourneyUbuntu's Official Flavours: Why Fewer Can Be BetterHASH Launches Free Online Platform for Simulating Complex Real-World SystemsHow Massachusetts Locked in $1.4 Billion in Offshore Wind Savings: A Step-by-Step GuideHow to Harness the Hunting Power of the Pink Floyd Spider for Natural Pest Control