[turbo-tasks] Experiment: capture snapshot pending bits under exclusion (#99747)
## Summary
This experiment builds on the copy-on-write snapshot design from #99649,
which is now on canary. It holds the operation exclusion while
`take_snapshot` runs, so the scan can move modified bits into new
`meta_snapshot_pending` / `data_snapshot_pending` bits safely.
Holding the exclusion means a task touched for the first time during the
snapshot doesn't need a `None` placeholder in `snapshots`. The map now
stores only copy-on-write `SnapshotItem`s, and `end_snapshot` just
leaves snapshot mode and clears the map. It no longer has to promote
during-snapshot flags or take paired shard locks.
Why: compare this simpler bookkeeping with #99649's approach, which
keeps the scan outside the exclusion. The trade-off is that operations
stay blocked during the O(N) capture scan. Encoding still happens later
in the snapshot iterators, after the exclusion is released. This design
was rejected earlier on #99649 ("delaying the snapshot to set these bits
is not acceptable"), so this PR is meant for comparison, not as the
assumed final direction.
How:
- The scan moves the modified bits into pending bits and records each
captured task.
- The first mutation of a captured task encodes all of its pending
categories before the mutation, so cases where different categories
change in different orders are covered.
- Pending bits stay set until the iterator yields the task. Undo and
eviction still see those bits until then.
- Shutdown drain mode still uses the modified bits directly.
- If persisting stops early (an error or a panic), each dropped shard
clears the pending bits of its captured tasks that weren't yielded,
before `end_snapshot` clears `snapshot_mode`. Pending bits never outlive
a snapshot, so `track_modification` decides copy-on-write from the
pending bits and the map alone, without reading `snapshot_mode`. The
iterator removes a task from its list only after it has finished with
that task, so a panic while encoding is cleaned up too.
- The snapshot callbacks take a `TaskDataCategory` (`Meta` / `Data` /
`All`) instead of a two-bool mask, because a persisted task always has
at least one category.
- The lower-layer changes are kept: the local copy-on-write buffer,
stats on encoded items, and `LastPersistenceStatus`.
## Verification
- `cargo test -p turbo-tasks-backend`
- `cargo test -p turbo-tasks-macros-tests`
- `cargo test -p turbo-tasks-backend --lib --features
verify_serialization,print_cache_item_size`
- `cargo clippy -p turbo-tasks-backend --all-targets -- -D warnings`,
with default features and with
`verify_serialization,print_cache_item_size`
- Mutation check: skipping copy-on-write for tasks with pending bits
made 6 tests fail. One of them shows the persisted meta bytes no longer
matching the captured meta.
- Failed-persist cleanup:
`dropping_shards_early_leaves_no_copy_on_write_items` and
`panic_while_encoding_clears_pending_flags` both failed before the
shard-drop cleanup existed. Emptying the `Drop` cleanup makes both fail
again. Removing a task from the list before encoding it makes only the
panic test fail. The panic test is skipped on wasm, which can't unwind;
the early-drop test still runs there.
- wasm: `cargo test -p turbo-tasks-backend --lib --target
wasm32-wasip1-threads` under `scripts/wasi-test-host` passes (108
passed, 14 ignored).
- Not run: benchmarks of how long the exclusion lasts or how long a full
snapshot takes. Holding the scan under the exclusion is a deliberate
trade-off here.
- Not run: `pnpm build-all` (this worktree has no `node_modules`).
<!-- 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.
Please
register
or
sign in
to comment