Skip to content

[turbopack] Store TaskDirtyCause in Dirtyness and pass to NativeFunction::span#94057

Merged
sokra merged 3 commits into
canaryfrom
sokra/task-dirty-cause
May 29, 2026
Merged

[turbopack] Store TaskDirtyCause in Dirtyness and pass to NativeFunction::span#94057
sokra merged 3 commits into
canaryfrom
sokra/task-dirty-cause

Conversation

@sokra
Copy link
Copy Markdown
Member

@sokra sokra commented May 22, 2026

What?

Track the cause of task invalidation in turbo-tasks and surface it to the tracing span when a task executes, so traces can show why a task was re-run.

A new task_dirty_cause Cargo feature gates the storage and parameter plumbing for this information. The existing trace_task_dirty feature now depends on it.

Why?

When investigating Turbopack performance and incremental-recompute behavior, traces show which tasks ran but not what invalidated them. Recording the TaskDirtyCause on the turbo_tasks::function span makes it possible to attribute task re-runs to their triggering change (cell update, output change, collectible change, etc.) directly from a trace.

How?

  • Replace Dirtyness::Dirty(TaskPriority) with a struct variant Dirty { parent_priority, cause: TaskDirtyCause }. The cause field is only present when the task_dirty_cause feature is enabled.
  • Move TaskDirtyCause from turbo-tasks-backend into turbo-tasks so the span signature in turbo-tasks can reference it.
  • Replace OutputChange { task_description } with OutputChange { function: FunctionId }, and add a new ResolveOutputChange { function: FunctionId } variant used when the task's output is OutputValue::Output(_). This avoids constructing a String for the cause at invalidation time.
  • NativeFunction::span now accepts a feature-gated cause: Option<&TaskDirtyCause> argument and records it as a cause field on the turbo_tasks::function span. The cause is read from the dirty state in try_start_task_execution before execution starts.
  • Split the trace_task_dirty feature: the new task_dirty_cause feature owns the storage/parameter plumbing, and trace_task_dirty now depends on it. This lets consumers opt into the storage cost without the full tracing overhead, and keeps the default build unaffected.

Closes PACK-

…ion::span

Track the cause of task invalidation in `Dirtyness::Dirty` (gated by a new
`task_dirty_cause` feature) and surface it to the tracing span when the
task executes, so traces can show why a task was re-run.

- Replace `Dirtyness::Dirty(TaskPriority)` with a struct variant
  `Dirty { parent_priority, cause: TaskDirtyCause }` where `cause` is only
  present under the `task_dirty_cause` feature.
- Move `TaskDirtyCause` from `turbo-tasks-backend` into `turbo-tasks` so the
  span signature can reference it. Replace `OutputChange.task_description`
  with `OutputChange { function: FunctionId }` and add a new
  `ResolveOutputChange { function: FunctionId }` variant used when the
  task's output is `OutputValue::Output(_)`.
- `NativeFunction::span` now takes a feature-gated
  `cause: Option<&TaskDirtyCause>` argument and records it as a `cause`
  field on `turbo_tasks::function`. The `cause` is read from the dirty
  state in `try_start_task_execution` before execution starts.
- Split the `trace_task_dirty` feature: the new `task_dirty_cause`
  feature owns the storage/parameter plumbing, and `trace_task_dirty`
  now depends on it.
@sokra sokra requested a review from lukesandberg May 22, 2026 19:12
@sokra sokra marked this pull request as ready for review May 22, 2026 19:12
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Tests Passed

Commit: bb70074

@sokra sokra requested a review from mischnic May 26, 2026 21:02
@sokra sokra enabled auto-merge (squash) May 26, 2026 21:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

Stats skipped

Commit: bb70074
View workflow run

@sokra sokra merged commit 24e8c18 into canary May 29, 2026
162 of 164 checks passed
@sokra sokra deleted the sokra/task-dirty-cause branch May 29, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants