Unverified Commit 72a32c34 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: use batch insert to make dependencies outdated (#85625)

### What?

Refactor making dependencies outdated and use batch add
parent d7608f7e
...@@ -1672,48 +1672,45 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1672,48 +1672,45 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
if self.should_track_dependencies() { if self.should_track_dependencies() {
// Make all dependencies outdated // Make all dependencies outdated
enum Dep { let outdated_cell_dependencies_to_add =
CurrentCell(CellRef), iter_many!(task, CellDependency { target } => target)
CurrentOutput(TaskId), .collect::<SmallVec<[_; 8]>>();
OutdatedCell(CellRef), let outdated_cell_dependencies_to_remove =
OutdatedOutput(TaskId), iter_many!(task, OutdatedCellDependency { target } => target)
.filter(|&target| {
!task.has_key(&CachedDataItemKey::CellDependency { target })
})
.collect::<SmallVec<[_; 8]>>();
task.extend(
CachedDataItemType::OutdatedCellDependency,
outdated_cell_dependencies_to_add
.into_iter()
.map(|target| CachedDataItem::OutdatedCellDependency { target, value: () }),
);
for target in outdated_cell_dependencies_to_remove {
task.remove(&CachedDataItemKey::OutdatedCellDependency { target });
} }
let dependencies = iter_many!(task, CellDependency { target } => Dep::CurrentCell(target))
.chain(iter_many!(task, OutputDependency { target } => Dep::CurrentOutput(target))) let outdated_output_dependencies_to_add =
.chain(iter_many!(task, OutdatedCellDependency { target } => Dep::OutdatedCell(target))) iter_many!(task, OutputDependency { target } => target)
.chain(iter_many!(task, OutdatedOutputDependency { target } => Dep::OutdatedOutput(target))) .collect::<SmallVec<[_; 8]>>();
.collect::<Vec<_>>(); let outdated_output_dependencies_to_remove =
for dep in dependencies { iter_many!(task, OutdatedOutputDependency { target } => target)
match dep { .filter(|&target| {
Dep::CurrentCell(cell) => { !task.has_key(&CachedDataItemKey::OutputDependency { target })
let _ = task.add(CachedDataItem::OutdatedCellDependency { })
target: cell, .collect::<SmallVec<[_; 8]>>();
value: (), task.extend(
}); CachedDataItemType::OutdatedOutputDependency,
} outdated_output_dependencies_to_add
Dep::CurrentOutput(output) => { .into_iter()
let _ = task.add(CachedDataItem::OutdatedOutputDependency { .map(|target| CachedDataItem::OutdatedOutputDependency {
target: output, target,
value: (), value: (),
}); }),
} );
Dep::OutdatedCell(cell) => { for target in outdated_output_dependencies_to_remove {
if !task.has_key(&CachedDataItemKey::CellDependency { target: cell }) { task.remove(&CachedDataItemKey::OutdatedOutputDependency { target });
task.remove(&CachedDataItemKey::OutdatedCellDependency {
target: cell,
});
}
}
Dep::OutdatedOutput(output) => {
if !task
.has_key(&CachedDataItemKey::OutputDependency { target: output })
{
task.remove(&CachedDataItemKey::OutdatedOutputDependency {
target: output,
});
}
}
}
} }
} }
} }
...@@ -1949,21 +1946,27 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1949,21 +1946,27 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let old_counters: FxHashMap<_, _> = let old_counters: FxHashMap<_, _> =
get_many!(task, CellTypeMaxIndex { cell_type } max_index => (cell_type, *max_index)); get_many!(task, CellTypeMaxIndex { cell_type } max_index => (cell_type, *max_index));
let mut counters_to_remove = old_counters.clone(); let mut counters_to_remove = old_counters.clone();
for (&cell_type, &max_index) in cell_counters.iter() {
if let Some(old_max_index) = counters_to_remove.remove(&cell_type) { task.extend(
if old_max_index != max_index { CachedDataItemType::CellTypeMaxIndex,
task.insert(CachedDataItem::CellTypeMaxIndex { cell_counters.iter().filter_map(|(&cell_type, &max_index)| {
if let Some(old_max_index) = counters_to_remove.remove(&cell_type) {
if old_max_index != max_index {
Some(CachedDataItem::CellTypeMaxIndex {
cell_type,
value: max_index,
})
} else {
None
}
} else {
Some(CachedDataItem::CellTypeMaxIndex {
cell_type, cell_type,
value: max_index, value: max_index,
}); })
} }
} else { }),
task.add_new(CachedDataItem::CellTypeMaxIndex { );
cell_type,
value: max_index,
});
}
}
for (cell_type, _) in counters_to_remove { for (cell_type, _) in counters_to_remove {
task.remove(&CachedDataItemKey::CellTypeMaxIndex { cell_type }); task.remove(&CachedDataItemKey::CellTypeMaxIndex { cell_type });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment