Skip to content

Commit 8d6db4c

Browse files
committed
more fast path
1 parent a3f2f98 commit 8d6db4c

File tree

1 file changed

+49
-46
lines changed
  • turbopack/crates/turbo-tasks-backend/src/backend/operation

1 file changed

+49
-46
lines changed

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

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,60 +52,63 @@ impl UpdateCellOperation {
5252
task.has_key(&CachedDataItemKey::Stateful {}));
5353

5454
if should_invalidate {
55-
// Slow path: We need to invalidate tasks depending on this cell.
56-
// To avoid a race condition, we need to remove the old content first,
57-
// then invalidate dependent tasks and only then update the cell content.
58-
59-
let old_content = task.remove(&CachedDataItemKey::CellData { cell });
60-
61-
let dependent_tasks = get_many!(
55+
let dependent_tasks: SmallVec<[TaskId; 4]> = get_many!(
6256
task,
6357
CellDependent { cell: dependent_cell, task }
6458
if dependent_cell == cell
6559
=> task
6660
);
6761

68-
drop(task);
69-
drop(old_content);
70-
71-
let content = if let CellContent(Some(new_content)) = content {
72-
Some(new_content.into_typed(cell.type_id))
73-
} else {
74-
None
75-
};
76-
77-
UpdateCellOperation::InvalidateWhenCellDependency {
78-
cell_ref: CellRef {
79-
task: task_id,
80-
cell,
81-
},
82-
dependent_tasks,
83-
content,
84-
queue: AggregationUpdateQueue::new(),
62+
if !dependent_tasks.is_empty() {
63+
// Slow path: We need to invalidate tasks depending on this cell.
64+
// To avoid a race condition, we need to remove the old content first,
65+
// then invalidate dependent tasks and only then update the cell content.
66+
67+
let old_content = task.remove(&CachedDataItemKey::CellData { cell });
68+
69+
drop(task);
70+
drop(old_content);
71+
72+
let content = if let CellContent(Some(new_content)) = content {
73+
Some(new_content.into_typed(cell.type_id))
74+
} else {
75+
None
76+
};
77+
78+
UpdateCellOperation::InvalidateWhenCellDependency {
79+
cell_ref: CellRef {
80+
task: task_id,
81+
cell,
82+
},
83+
dependent_tasks,
84+
content,
85+
queue: AggregationUpdateQueue::new(),
86+
}
87+
.execute(&mut ctx);
88+
return;
8589
}
86-
.execute(&mut ctx);
90+
}
91+
92+
// Fast path: We don't need to invalidate anything.
93+
// So we can just update the cell content.
94+
95+
let old_content = if let CellContent(Some(new_content)) = content {
96+
let new_content = new_content.into_typed(cell.type_id);
97+
task.insert(CachedDataItem::CellData {
98+
cell,
99+
value: new_content,
100+
})
87101
} else {
88-
// Fast path: We don't need to invalidate anything.
89-
// So we can just update the cell content.
90-
91-
let old_content = if let CellContent(Some(new_content)) = content {
92-
let new_content = new_content.into_typed(cell.type_id);
93-
task.insert(CachedDataItem::CellData {
94-
cell,
95-
value: new_content,
96-
})
97-
} else {
98-
task.remove(&CachedDataItemKey::CellData { cell })
99-
};
100-
101-
let in_progress_cell = remove!(task, InProgressCell { cell });
102-
103-
drop(task);
104-
drop(old_content);
105-
106-
if let Some(in_progress) = in_progress_cell {
107-
in_progress.event.notify(usize::MAX);
108-
}
102+
task.remove(&CachedDataItemKey::CellData { cell })
103+
};
104+
105+
let in_progress_cell = remove!(task, InProgressCell { cell });
106+
107+
drop(task);
108+
drop(old_content);
109+
110+
if let Some(in_progress) = in_progress_cell {
111+
in_progress.event.notify(usize::MAX);
109112
}
110113
}
111114
}

0 commit comments

Comments
 (0)