turbopack/crates/turbo-tasks/README.md
An incremental computation system that uses macros and types to automate the caching process.
For a high-level overview, start by reading Inside Turbopack: Building Faster by Building Less.
Turbo Tasks defines 4 primitives:
It defines some derived elements from that:
Vcs ("Value Cells"): References to locations associated with tasks where values are stored. The contents of a cell can change after the reexecution of a function due to invalidation. A Vc can be read to get [a read-only reference][crate::ReadRef] to the stored data, representing a snapshot of that cell at that point in time.There are a few design patterns that are commonly used with Turbo Tasks:
[#[turbo_tasks::function]][crate::function]s are memoized functions within the build process. An instance of a function with arguments is called a task. They are responsible for:
Vc<T>][crate::Vc] (Value Cell) is awaited.All tasks and their dependencies form a task graph.
This graph is crucial for invalidation propagation. When a task is invalidated, the changes propagate through the graph, triggering rebuilds where necessary.
Upon execution of functions, turbo-tasks will track which Vcs are read. Once any of these change, turbo-tasks will invalidate the task created from the function's execution and it will eventually be scheduled and reexecuted.
After initial execution, turbo-tasks employs a bottom-up approach for incremental rebuilds.
By rebuilding invalidated tasks, only the parts of the graph affected by changes are rebuilt, leaving untouched parts intact. No work is done for unchanged parts.