turbo-tasks-backend: parent_count reference counting (#95976)
Adds the reference counting that lets the backend know when a task has become unreachable. ### What this adds Two inline counts on `TaskStorage`, maintained incrementally so a task's reachability is known the moment its last parent drops — with no DB scan: - **`parent_count`** (meta, persisted) — how many persistent parents list this task in their `children` set. Reaching 0 means the task is unreachable from persistent roots. - **`transient_ref_count`** (transient) — session-only references that aren't persistent parent edges: a transient parent's child edge, or a detached handle held outside the tracked graph. Never persisted; re-established on restart. Maintenance happens at the two `children`-edge mutation sites: - `connect_children` applies the `+1` directly under the child guard it already takes. It has to land before the first `operation_suspend_point` so the new child edge and the `+1` are atomically observable. - `CleanupOldEdges` queues the `-1` as an aggregation-update job, which takes the child guards itself rather than nesting a second guard under the parent's. `AdjustParentCount` is durably encoded so an in-flight delta replays after a crash and the persisted count stays consistent. `AdjustTransientRefCount` is `bincode(skip)` and collapses to `Noop`, like the other transient active-count jobs. ### Two things worth a closer look **`output_dependent`'s inline capacity drops from 6 to 4.** `test_schema_size` asserts `TaskStorage` is exactly 128 bytes, and the two new `u32`s add 8. `AutoSet<TaskId, 6>` is 32 B and `AutoSet<TaskId, 4>` is 24 B, freeing exactly the 8 needed (capacity 5 is still 32 B, so 4 is the first that fits). This is a real behavior change, not just a layout tweak: a task with 5 or 6 output dependents now spills to the heap where it previously stayed inline. **`task_execution_completed_unfinished_children_dirty` is gone.** Since `connect_children` now takes a guard on every new child anyway, the "mark children with no output dirty" pass folds into that same loop — one guard acquisition instead of two. Behavior-preserving relocation, but it does mean the dirty-marking now reads as part of the connect path. ### Testing `tests/parent_count.rs` covers the count reaching the right value through connect/disconnect, the parallel wide-fanout `connect_children` path, revalidation not double-counting, survival across a snapshot + eviction, and survival across a full DB reopen (the count is persisted meta, and an in-flight `AdjustParentCount` replays via the durable queue). Each of the four commits builds and tests green on its own.
Showing
Please
register
or
sign in
to comment