Inside Turbopack: Building Faster by Building Less
Key Points
- Fine-grained incremental caching
- Automatic dependency tracking with value cells
- Persistent file-system cache (Next.js 16.1)
Summary
Turbopack is an incremental, fine‑grained bundler built as the new default for Next.js to enable instant builds and fast as-you-type iteration. It uses automatic dependency tracking (value cells), demand-driven dirty propagation, and an aggregation graph to scale to very large apps while minimizing recomputation. Next.js 16.1 introduced on-by-default file-system caching for next dev to persist the dependency/aggregation graphs and intermediate results.
Key Points
- Fine-grained automatic caching: Turbopack represents nearly every internal piece of work as value cells that record dependencies when read, enabling minimal recomputation for small changes.
- Demand-driven recomputation: When files change, functions that read affected cells are marked dirty and only re-executed when part of an active query (e.g., an open page or a production build) to avoid wasted work.
- Aggregation graph: A layered summary structure lets the system efficiently query and collect information (errors, dirty subgraphs, etc.) without traversing millions of fine-grained nodes.
- File-system cache (Next.js 16.1): The dependency graph, aggregation graph, and value-cell contents can be persisted to disk so dev sessions resume warm and fast.
- Trade-offs and risks: Incremental caching increases implementation complexity and can add CPU/memory and disk overhead; poor caching strategies can regress performance or introduce bugs.
Practical implications for engineers
- Expect much faster iteration for small changes; rebuild cost scales with change size, not project size.
- Enable and monitor the file-system cache for local dev to maximize warm start benefits (added in Next.js 16.1).
- Monitor cache size and correctness; be mindful of added complexity when integrating custom plugins or transforms.
- Use Turbopack for large apps where whole-program bundling and tree-shaking benefit from fine-grained incremental recomputation.