turbo-tasks: update reader leaf distance inline when adding output dependency (#99764)
### What? Updates the reader's leaf distance inline when `try_read_task_output` adds a new output-dependency edge. The `LeafDistanceUpdateQueue` is only used to propagate to the reader's existing output dependents. ### Why? The reader is already locked (with the `All` category) while the edge is added. Before this change, the code allocated a fresh `LeafDistanceUpdateQueue` and pushed the reader into it. After dropping the guards it locked the reader again, just to update one field. In the common case the reader has no output dependents yet, so all of that work was redundant. This path runs for each new edge whose reader's distance is not already greater than the dependency's, which is common in cold builds with dependency tracking enabled. ### How? - The leaf-distance arithmetic now lives in a single `compute_leaf_distance_update`, used by both the queue and the inline path. The arithmetic itself is unchanged. - At the call site: - The new distance is written on the reader guard that is already held. - Output-dependent IDs are snapshotted into a `SmallVec`. - The paired-lock dependency registration is unchanged. - The queue is only created, seeded and executed after both guards are dropped. - The `trace_leaf_distance_update` tracing stays supported via an inline span. ### Verification - New behavioral unit tests for how leaf distance propagates: - a reader that is already ahead of its dependency is not updated; - a reader at or behind its dependency moves past it; - updates inside the buffer zone keep the buffer ceiling; - dependents are seeded with the reader's new distance. - `cargo nextest run -p turbo-tasks-backend`: 291/291 pass. - The existing ungated `collector_is_not_re_executed_for_collectibles_it_has_not_read_yet` test is load-sensitive on unmodified `canary` too: it failed 91 of 120 runs with 4 copies in parallel. It flaked once locally during the rebase; it did not fail in later runs. - `cargo test -p turbo-tasks --lib`: 127/127 pass. - `cargo check --tests` passes both with and without `--features trace_leaf_distance_update`. - `cargo clippy -p turbo-tasks-backend --tests -- -D warnings` passes. Not run: a real build benchmark. This removes a redundant lock and allocations on the hot path; no build-time speedup is claimed or measured. <!-- NEXT_JS_LLM --> <!-- fleet b792e520-57be-40bf-8385-fad7b8fc11aa --> --------- 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>
Showing
Please
register
or
sign in
to comment