Skip to content

Commit 227cf5f

Browse files
authored
put dirty task tracing behind a feature flag (#75022)
### What? Reduces the tracing verbosity by putting some of the internal tracing behind a feature flag
1 parent c7a87bf commit 227cf5f

File tree

8 files changed

+109
-34
lines changed

8 files changed

+109
-34
lines changed

turbopack/crates/turbo-tasks-backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ default = []
1717
verify_serialization = []
1818
trace_aggregation_update = []
1919
trace_find_and_schedule = []
20+
trace_task_dirty = []
2021
lmdb = ["dep:lmdb-rkv"]
2122

2223
[dependencies]

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ use turbo_tasks::{
3636
};
3737

3838
pub use self::{operation::AnyOperation, storage::TaskDataCategory};
39+
#[cfg(feature = "trace_task_dirty")]
40+
use crate::backend::operation::TaskDirtyCause;
3941
use crate::{
4042
backend::{
4143
operation::{
4244
get_aggregation_number, is_root_node, AggregatedDataUpdate, AggregationUpdateJob,
4345
AggregationUpdateQueue, CleanupOldEdgesOperation, ConnectChildOperation,
44-
ExecuteContext, ExecuteContextImpl, Operation, OutdatedEdge, TaskDirtyCause, TaskGuard,
46+
ExecuteContext, ExecuteContextImpl, Operation, OutdatedEdge, TaskGuard,
4547
},
4648
persisted_storage_log::PersistedStorageLog,
4749
storage::{get, get_many, get_mut, get_mut_or_insert_with, iter_many, remove, Storage},
@@ -901,6 +903,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
901903
}
902904
operation::InvalidateOperation::run(
903905
smallvec![task_id],
906+
#[cfg(feature = "trace_task_dirty")]
904907
TaskDirtyCause::Invalidator,
905908
self.execute_context(turbo_tasks),
906909
);
@@ -916,6 +919,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
916919
}
917920
operation::InvalidateOperation::run(
918921
tasks.iter().copied().collect(),
922+
#[cfg(feature = "trace_task_dirty")]
919923
TaskDirtyCause::Unknown,
920924
self.execute_context(turbo_tasks),
921925
);
@@ -931,6 +935,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
931935
}
932936
operation::InvalidateOperation::run(
933937
tasks.iter().copied().collect(),
938+
#[cfg(feature = "trace_task_dirty")]
934939
TaskDirtyCause::Unknown,
935940
self.execute_context(turbo_tasks),
936941
);
@@ -1291,7 +1296,11 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12911296
.get(&cell.type_id)
12921297
.is_none_or(|start_index| cell.index >= *start_index) =>
12931298
{
1294-
Some(OutdatedEdge::RemovedCellDependent(task, cell.type_id))
1299+
Some(OutdatedEdge::RemovedCellDependent {
1300+
task_id: task,
1301+
#[cfg(feature = "trace_task_dirty")]
1302+
value_type_id: cell.type_id,
1303+
})
12951304
}
12961305
_ => None,
12971306
}

turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ use smallvec::SmallVec;
1414
feature = "trace_find_and_schedule"
1515
))]
1616
use tracing::{span::Span, trace_span};
17-
use turbo_tasks::{FxIndexMap, SessionId, TaskId, TraitTypeId};
17+
use turbo_tasks::{FxIndexMap, SessionId, TaskId};
1818

19+
#[cfg(feature = "trace_task_dirty")]
20+
use crate::backend::operation::invalidate::TaskDirtyCause;
1921
use crate::{
2022
backend::{
2123
get_mut, get_mut_or_insert_with,
22-
operation::{
23-
invalidate::{make_task_dirty, TaskDirtyCause},
24-
ExecuteContext, Operation, TaskGuard,
25-
},
24+
operation::{invalidate::make_task_dirty, ExecuteContext, Operation, TaskGuard},
2625
storage::{
2726
count, get, get_many, iter_many, remove, update, update_count, update_ucount_and_get,
2827
},
@@ -138,7 +137,8 @@ pub enum AggregationUpdateJob {
138137
/// Invalidates tasks that are dependent on a collectible type.
139138
InvalidateDueToCollectiblesChange {
140139
task_ids: SmallVec<[TaskId; 4]>,
141-
collectible_type: TraitTypeId,
140+
#[cfg(feature = "trace_task_dirty")]
141+
collectible_type: turbo_tasks::TraitTypeId,
142142
},
143143
/// Increases the active counter of the task
144144
IncreaseActiveCount { task: TaskId },
@@ -349,6 +349,7 @@ impl AggregatedDataUpdate {
349349
if !dependent.is_empty() {
350350
queue.push(AggregationUpdateJob::InvalidateDueToCollectiblesChange {
351351
task_ids: dependent,
352+
#[cfg(feature = "trace_task_dirty")]
352353
collectible_type: ty,
353354
})
354355
}
@@ -783,11 +784,13 @@ impl AggregationUpdateQueue {
783784
}
784785
AggregationUpdateJob::InvalidateDueToCollectiblesChange {
785786
task_ids,
787+
#[cfg(feature = "trace_task_dirty")]
786788
collectible_type,
787789
} => {
788790
for task_id in task_ids {
789791
make_task_dirty(
790792
task_id,
793+
#[cfg(feature = "trace_task_dirty")]
791794
TaskDirtyCause::CollectiblesChange { collectible_type },
792795
self,
793796
ctx,

turbopack/crates/turbo-tasks-backend/src/backend/operation/cleanup_old_edges.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::mem::take;
22

33
use serde::{Deserialize, Serialize};
4-
use turbo_tasks::{TaskId, ValueTypeId};
4+
use turbo_tasks::TaskId;
55

6+
#[cfg(feature = "trace_task_dirty")]
7+
use crate::backend::operation::invalidate::TaskDirtyCause;
68
use crate::{
79
backend::{
810
get,
@@ -11,7 +13,7 @@ use crate::{
1113
get_aggregation_number, get_uppers, is_aggregating_node, AggregationUpdateJob,
1214
AggregationUpdateQueue,
1315
},
14-
invalidate::{make_task_dirty, TaskDirtyCause},
16+
invalidate::make_task_dirty,
1517
AggregatedDataUpdate, ExecuteContext, Operation, TaskGuard,
1618
},
1719
storage::update_count,
@@ -42,7 +44,11 @@ pub enum OutdatedEdge {
4244
CellDependency(CellRef),
4345
OutputDependency(TaskId),
4446
CollectiblesDependency(CollectiblesRef),
45-
RemovedCellDependent(TaskId, ValueTypeId),
47+
RemovedCellDependent {
48+
task_id: TaskId,
49+
#[cfg(feature = "trace_task_dirty")]
50+
value_type_id: turbo_tasks::ValueTypeId,
51+
},
4652
}
4753

4854
impl CleanupOldEdgesOperation {
@@ -185,10 +191,17 @@ impl Operation for CleanupOldEdgesOperation {
185191
});
186192
}
187193
}
188-
OutdatedEdge::RemovedCellDependent(task_id, value_type) => {
194+
OutdatedEdge::RemovedCellDependent {
195+
task_id,
196+
#[cfg(feature = "trace_task_dirty")]
197+
value_type_id,
198+
} => {
189199
make_task_dirty(
190200
task_id,
191-
TaskDirtyCause::CellRemoved { value_type },
201+
#[cfg(feature = "trace_task_dirty")]
202+
TaskDirtyCause::CellRemoved {
203+
value_type: value_type_id,
204+
},
192205
queue,
193206
ctx,
194207
);

turbopack/crates/turbo-tasks-backend/src/backend/operation/invalidate.rs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::fmt::Display;
2-
31
use serde::{Deserialize, Serialize};
42
use smallvec::SmallVec;
5-
use turbo_tasks::{registry, TaskId, TraitTypeId, ValueTypeId};
3+
use turbo_tasks::TaskId;
64

75
use crate::{
86
backend::{
@@ -24,6 +22,7 @@ pub enum InvalidateOperation {
2422
// TODO DetermineActiveness
2523
MakeDirty {
2624
task_ids: SmallVec<[TaskId; 4]>,
25+
#[cfg(feature = "trace_task_dirty")]
2726
cause: TaskDirtyCause,
2827
},
2928
AggregationUpdate {
@@ -36,10 +35,15 @@ pub enum InvalidateOperation {
3635
impl InvalidateOperation {
3736
pub fn run(
3837
task_ids: SmallVec<[TaskId; 4]>,
39-
cause: TaskDirtyCause,
38+
#[cfg(feature = "trace_task_dirty")] cause: TaskDirtyCause,
4039
mut ctx: impl ExecuteContext,
4140
) {
42-
InvalidateOperation::MakeDirty { task_ids, cause }.execute(&mut ctx)
41+
InvalidateOperation::MakeDirty {
42+
task_ids,
43+
#[cfg(feature = "trace_task_dirty")]
44+
cause,
45+
}
46+
.execute(&mut ctx)
4347
}
4448
}
4549

@@ -48,10 +52,20 @@ impl Operation for InvalidateOperation {
4852
loop {
4953
ctx.operation_suspend_point(&self);
5054
match self {
51-
InvalidateOperation::MakeDirty { task_ids, cause } => {
55+
InvalidateOperation::MakeDirty {
56+
task_ids,
57+
#[cfg(feature = "trace_task_dirty")]
58+
cause,
59+
} => {
5260
let mut queue = AggregationUpdateQueue::new();
5361
for task_id in task_ids {
54-
make_task_dirty(task_id, cause, &mut queue, ctx);
62+
make_task_dirty(
63+
task_id,
64+
#[cfg(feature = "trace_task_dirty")]
65+
cause,
66+
&mut queue,
67+
ctx,
68+
);
5569
}
5670
if queue.is_empty() {
5771
self = InvalidateOperation::Done
@@ -73,23 +87,34 @@ impl Operation for InvalidateOperation {
7387
}
7488
}
7589

90+
#[cfg(feature = "trace_task_dirty")]
7691
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
7792
pub enum TaskDirtyCause {
7893
InitialDirty,
79-
CellChange { value_type: ValueTypeId },
80-
CellRemoved { value_type: ValueTypeId },
81-
OutputChange { task_id: TaskId },
82-
CollectiblesChange { collectible_type: TraitTypeId },
94+
CellChange {
95+
value_type: turbo_tasks::ValueTypeId,
96+
},
97+
CellRemoved {
98+
value_type: turbo_tasks::ValueTypeId,
99+
},
100+
OutputChange {
101+
task_id: TaskId,
102+
},
103+
CollectiblesChange {
104+
collectible_type: turbo_tasks::TraitTypeId,
105+
},
83106
Invalidator,
84107
Unknown,
85108
}
86109

110+
#[cfg(feature = "trace_task_dirty")]
87111
struct TaskDirtyCauseInContext<'l, 'e, E: ExecuteContext<'e>> {
88112
cause: &'l TaskDirtyCause,
89113
ctx: &'l E,
90114
_phantom: std::marker::PhantomData<&'e ()>,
91115
}
92116

117+
#[cfg(feature = "trace_task_dirty")]
93118
impl<'l, 'e, E: ExecuteContext<'e>> TaskDirtyCauseInContext<'l, 'e, E> {
94119
fn new(cause: &'l TaskDirtyCause, ctx: &'l E) -> Self {
95120
Self {
@@ -100,22 +125,23 @@ impl<'l, 'e, E: ExecuteContext<'e>> TaskDirtyCauseInContext<'l, 'e, E> {
100125
}
101126
}
102127

103-
impl<'e, E: ExecuteContext<'e>> Display for TaskDirtyCauseInContext<'_, 'e, E> {
128+
#[cfg(feature = "trace_task_dirty")]
129+
impl<'e, E: ExecuteContext<'e>> std::fmt::Display for TaskDirtyCauseInContext<'_, 'e, E> {
104130
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
105131
match self.cause {
106132
TaskDirtyCause::InitialDirty => write!(f, "initial dirty"),
107133
TaskDirtyCause::CellChange { value_type } => {
108134
write!(
109135
f,
110136
"{} cell changed",
111-
registry::get_value_type(*value_type).name
137+
turbo_tasks::registry::get_value_type(*value_type).name
112138
)
113139
}
114140
TaskDirtyCause::CellRemoved { value_type } => {
115141
write!(
116142
f,
117143
"{} cell removed",
118-
registry::get_value_type(*value_type).name
144+
turbo_tasks::registry::get_value_type(*value_type).name
119145
)
120146
}
121147
TaskDirtyCause::OutputChange { task_id } => {
@@ -129,7 +155,7 @@ impl<'e, E: ExecuteContext<'e>> Display for TaskDirtyCauseInContext<'_, 'e, E> {
129155
write!(
130156
f,
131157
"{} collectible changed",
132-
registry::get_trait(*collectible_type).name
158+
turbo_tasks::registry::get_trait(*collectible_type).name
133159
)
134160
}
135161
TaskDirtyCause::Invalidator => write!(f, "invalidator"),
@@ -140,7 +166,7 @@ impl<'e, E: ExecuteContext<'e>> Display for TaskDirtyCauseInContext<'_, 'e, E> {
140166

141167
pub fn make_task_dirty(
142168
task_id: TaskId,
143-
cause: TaskDirtyCause,
169+
#[cfg(feature = "trace_task_dirty")] cause: TaskDirtyCause,
144170
queue: &mut AggregationUpdateQueue,
145171
ctx: &mut impl ExecuteContext,
146172
) {
@@ -150,20 +176,29 @@ pub fn make_task_dirty(
150176

151177
let mut task = ctx.task(task_id, TaskDataCategory::All);
152178

153-
make_task_dirty_internal(&mut task, task_id, true, cause, queue, ctx);
179+
make_task_dirty_internal(
180+
&mut task,
181+
task_id,
182+
true,
183+
#[cfg(feature = "trace_task_dirty")]
184+
cause,
185+
queue,
186+
ctx,
187+
);
154188
}
155189

156190
pub fn make_task_dirty_internal(
157191
task: &mut impl TaskGuard,
158192
task_id: TaskId,
159193
make_stale: bool,
160-
cause: TaskDirtyCause,
194+
#[cfg(feature = "trace_task_dirty")] cause: TaskDirtyCause,
161195
queue: &mut AggregationUpdateQueue,
162196
ctx: &impl ExecuteContext,
163197
) {
164198
if make_stale {
165199
if let Some(InProgressState::InProgress { stale, .. }) = get_mut!(task, InProgress) {
166200
if !*stale {
201+
#[cfg(feature = "trace_task_dirty")]
167202
let _span = tracing::trace_span!(
168203
"make task stale",
169204
name = ctx.get_task_description(task_id),
@@ -185,6 +220,7 @@ pub fn make_task_dirty_internal(
185220
clean_in_session: None,
186221
},
187222
}) => {
223+
#[cfg(feature = "trace_task_dirty")]
188224
let _span = tracing::trace_span!(
189225
"task already dirty",
190226
name = ctx.get_task_description(task_id),
@@ -215,6 +251,7 @@ pub fn make_task_dirty_internal(
215251
_ => unreachable!(),
216252
};
217253

254+
#[cfg(feature = "trace_task_dirty")]
218255
let _span = tracing::trace_span!(
219256
"make task dirty",
220257
name = ctx.get_task_description(task_id),

turbopack/crates/turbo-tasks-backend/src/backend/operation/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,13 @@ impl_operation!(UpdateOutput update_output::UpdateOutputOperation);
742742
impl_operation!(CleanupOldEdges cleanup_old_edges::CleanupOldEdgesOperation);
743743
impl_operation!(AggregationUpdate aggregation_update::AggregationUpdateQueue);
744744

745+
#[cfg(feature = "trace_task_dirty")]
746+
pub use self::invalidate::TaskDirtyCause;
745747
pub use self::{
746748
aggregation_update::{
747749
get_aggregation_number, is_root_node, AggregatedDataUpdate, AggregationUpdateJob,
748750
},
749751
cleanup_old_edges::OutdatedEdge,
750-
invalidate::TaskDirtyCause,
751752
update_cell::UpdateCellOperation,
752753
update_collectible::UpdateCollectibleOperation,
753754
};

turbopack/crates/turbo-tasks-backend/src/backend/operation/update_cell.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use turbo_tasks::{backend::CellContent, CellId, TaskId};
22

3+
#[cfg(feature = "trace_task_dirty")]
4+
use crate::backend::operation::invalidate::TaskDirtyCause;
35
use crate::{
46
backend::{
5-
operation::{invalidate::TaskDirtyCause, ExecuteContext, InvalidateOperation, TaskGuard},
7+
operation::{ExecuteContext, InvalidateOperation, TaskGuard},
68
storage::{get_many, remove},
79
TaskDataCategory,
810
},
@@ -50,6 +52,7 @@ impl UpdateCellOperation {
5052

5153
InvalidateOperation::run(
5254
dependent,
55+
#[cfg(feature = "trace_task_dirty")]
5356
TaskDirtyCause::CellChange {
5457
value_type: cell.type_id,
5558
},

0 commit comments

Comments
 (0)