Skip to content

Commit

Permalink
[Turbopack] fix collectibles counting and aggregation (#72609)
Browse files Browse the repository at this point in the history
### What?

fix some bugs when counting collectibles
  • Loading branch information
sokra authored Nov 13, 2024
1 parent 4ac3b54 commit 08d771a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
9 changes: 9 additions & 0 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,15 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
_ => None,
},
));
old_edges.extend(task.iter(CachedDataItemIndex::Collectibles).filter_map(
|(key, value)| match (key, value) {
(
CachedDataItemKey::OutdatedCollectible { collectible },
CachedDataItemValue::OutdatedCollectible { value },
) => Some(OutdatedEdge::Collectible(*collectible, *value)),
_ => None,
},
));
}
if self.should_track_dependencies() {
old_edges.extend(task.iter(CachedDataItemIndex::Dependencies).filter_map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl AggregatedDataUpdate {
let aggregation = get_aggregation_number(task);
let mut dirty_container_count = Default::default();
let mut collectibles_update: Vec<_> =
get_many!(task, Collectible { collectible } => (*collectible, 1));
get_many!(task, Collectible { collectible } count => (*collectible, *count));
if is_aggregating_node(aggregation) {
dirty_container_count = get!(task, AggregatedDirtyContainerCount)
.cloned()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Operation for CleanupOldEdgesOperation {
}
OutdatedEdge::Collectible(collectible, count) => {
let mut collectibles = Vec::new();
collectibles.push((collectible, count));
collectibles.push((collectible, -count));
outdated.retain(|e| match e {
OutdatedEdge::Collectible(collectible, count) => {
collectibles.push((*collectible, -*count));
Expand All @@ -108,8 +108,14 @@ impl Operation for CleanupOldEdgesOperation {
_ => true,
});
let mut task = ctx.task(task_id, TaskDataCategory::All);
for &(collectible, count) in collectibles.iter() {
update_count!(task, Collectible { collectible }, -count);
for (collectible, count) in collectibles.iter_mut() {
update_count!(
task,
Collectible {
collectible: *collectible
},
*count
);
}
queue.extend(AggregationUpdateJob::data_update(
&mut task,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl UpdateCollectibleOperation {
pub fn run(
task_id: TaskId,
collectible: CollectibleRef,
count: i32,
mut count: i32,
mut ctx: impl ExecuteContext,
) {
if !ctx.should_track_children() {
Expand All @@ -32,26 +32,24 @@ impl UpdateCollectibleOperation {
let outdated = get!(task, OutdatedCollectible { collectible }).copied();
if let Some(outdated) = outdated {
if count > 0 && outdated > 0 {
update_count!(
task,
OutdatedCollectible { collectible },
-min(count, outdated)
);
let shared = min(count, outdated);
update_count!(task, OutdatedCollectible { collectible }, -shared);
count -= shared;
} else if count < 0 && outdated < 0 {
update_count!(
task,
OutdatedCollectible { collectible },
min(-count, -outdated)
);
let shared = min(-count, -outdated);
update_count!(task, OutdatedCollectible { collectible }, shared);
count += shared;
} else {
// Not reduced from outdated
}
}
update_count!(task, Collectible { collectible }, count);
queue.extend(AggregationUpdateJob::data_update(
&mut task,
AggregatedDataUpdate::new().collectibles_update(vec![(collectible, count)]),
));
if count != 0 {
update_count!(task, Collectible { collectible }, count);
queue.extend(AggregationUpdateJob::data_update(
&mut task,
AggregatedDataUpdate::new().collectibles_update(vec![(collectible, count)]),
));
}

drop(task);

Expand Down

0 comments on commit 08d771a

Please sign in to comment.