32408
Environment & Energy

Turboshaft: Replacing the Sea of Nodes in V8's Compiler

Posted by u/Lolpro Lab · 2026-05-21 00:20:20

Introduction

For over a decade, V8's top-tier optimizing compiler, Turbofan, relied on a unique intermediate representation known as the Sea of Nodes (SoN). This graph-based approach, where instructions and data flow are intermingled, set V8 apart from most other production compilers. However, since 2021, the V8 team has been systematically replacing SoN with a more conventional Control-Flow Graph (CFG) based IR called Turboshaft. As of 2024, the entire JavaScript backend of Turbofan has transitioned to Turboshaft, and WebAssembly uses it throughout its pipeline. Only a few remnants of SoN remain: the builtin pipeline (being slowly replaced) and the frontend of the JavaScript pipeline (being replaced by Maglev, another CFG IR). This article explores the reasons behind this architectural shift.

Turboshaft: Replacing the Sea of Nodes in V8's Compiler
Source: v8.dev

The Path from Crankshaft to Turbofan and Sea of Nodes

Crankshaft's Limitations

Twelve years ago, in 2013, V8's only optimizing compiler was Crankshaft, which used a standard CFG IR. While it delivered significant performance improvements, it had several critical flaws:

  • Excessive hand-written assembly: Every new IR operator required manual assembly code for four architectures (x64, ia32, arm, arm64).
  • asm.js optimization struggles: At that time, asm.js was seen as a pathway to high-performance JavaScript, but Crankshaft couldn't optimize it effectively.
  • No control flow during lowerings: Control flow was fixed at graph-building time. For example, lowering a high-level operation like JSAdd(x, y) to a conditional string addition was impossible.
  • Try-catch support: Despite months of effort by multiple engineers, Crankshaft never supported try-catch blocks.
  • Performance cliffs and bailouts: Using certain features or edge cases could cause 100x performance drops, making code performance unpredictable.
  • Deoptimization loops: Crankshaft would reoptimize with the same speculative assumptions that caused deoptimization, leading to endless cycles.

Turbofan and the Adoption of Sea of Nodes

To overcome Crankshaft's limitations, V8 developed Turbofan, which adopted the Sea of Nodes representation. SoN elegantly combined data flow and control flow into a single graph, enabling more aggressive optimizations and flexible lowerings. It allowed operators to be reordered and control flow to be introduced later. This design solved many of Crankshaft's problems, including supporting try-catch and eliminating performance cliffs. SoN became the bedrock of V8's optimization pipeline for years.

Why Did V8 Abandon the Sea of Nodes?

Complexity and Maintenance Burden

Despite its theoretical elegance, SoN introduced significant complexity. The graph's structure made debugging, profiling, and reasoning about compiler passes much harder. Maintaining the compiler required deep expertise in SoN's intricacies, slowing down development. As V8 evolved, the team found that a CFG-based IR offered a better trade-off between expressiveness and maintainability.

Improved Compiler Architecture with Turboshaft

Turboshaft, the new CFG IR, was designed from the ground up to be simpler and more modular. It separates control flow and data flow, making passes easier to write and verify. This design reduces the risk of subtle bugs and enables faster iteration. The team reports that Turboshaft's structure leads to more predictable compilation and easier performance tuning.

Practical Benefits in Modern JavaScript

Modern JavaScript engines face evolving workloads, from web applications to WebAssembly. Turboshaft's CFG approach handles these workloads efficiently, especially for large functions and complex control flow. Benchmarks show that Turboshaft generates comparable or better code quality than SoN, while being simpler to maintain and extend.

Current Status of the Transition

Today, Turboshaft has fully replaced SoN in Turbofan's JavaScript backend. The WebAssembly pipeline also uses Turboshaft end-to-end. Two areas still rely on some SoN code: the builtin pipeline (gradually being migrated) and the JavaScript frontend (being replaced by Maglev, another CFG-based compiler). Maglev handles intermediate-tier optimization, reducing the load on Turbofan. Once these replacements are complete, Sea of Nodes will be completely phased out.

Conclusion

The shift from Sea of Nodes to Turboshaft marks a pragmatic evolution in V8's compiler design. While SoN was a groundbreaking innovation that solved many problems, its complexity eventually outweighed its benefits. Turboshaft provides a more maintainable, efficient, and developer-friendly foundation for future optimizations. This transition underscores the importance of balancing theoretical elegance with practical engineering realities in compiler development.