turbo-tasks: bincode-encode copy-on-write snapshots instead of cloning (#99644)
### What? When a task that is already part of an in-progress persistence snapshot is modified again, `track_modification_internal` now bincode-encodes the task's pre-mutation state into the `SnapshotItem` that persistence will write, and stores that in the `snapshots` map. Before, it stored a `clone_snapshot()` copy of the `TaskStorage`. ### Why? The copy-on-write path exists so persistence sees a consistent snapshot even if a task is mutated while the snapshot is being written. Cloning `TaskStorage` doesn't guarantee that: cell contents are held behind `SharedReference` (`Arc`), so the clone shares them with the live task. If a cell value has interior mutability, a later mutation shows up in the "frozen" copy and the persisted state is no longer consistent. Encoding the state right away captures plain bytes that later mutations can't reach. The snapshot iterator hands the stored item straight to persistence, so nothing is encoded twice. The only cost is holding the encoded buffers in memory until the racing persistence picks them up, and this race is rare. <!-- NEXT_JS_LLM --> <!-- fleet 98a896e8-00fa-4f81-97f0-48bd49e2a9a2 --> --------- Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Luke Sandberg <210140+lukesandberg@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
This diff is collapsed.
This diff is collapsed.
Please
register
or
sign in
to comment