Skip to content

Commit

Permalink
count already unloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jul 15, 2024
1 parent 91c44f9 commit ee2fb72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 11 additions & 10 deletions crates/turbo-tasks-memory/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ struct OldGeneration {
generation: NonZeroU32,
}

#[derive(Default)]
struct ProcessGenerationResult {
priority: Option<GcPriority>,
content_dropped_count: usize,
unloaded_count: usize,
already_unloaded_count: usize,
}

struct ProcessDeactivationsResult {
Expand Down Expand Up @@ -233,11 +235,7 @@ impl GcQueue {
}) = old_generation
else {
// No old generation to process
return ProcessGenerationResult {
priority: None,
content_dropped_count: 0,
unloaded_count: 0,
};
return ProcessGenerationResult::default();
};
// Check all tasks for the correct generation
let mut indices = Vec::with_capacity(tasks.len());
Expand All @@ -256,11 +254,7 @@ impl GcQueue {

if indices.is_empty() {
// No valid tasks in old generation to process
return ProcessGenerationResult {
priority: None,
content_dropped_count: 0,
unloaded_count: 0,
};
return ProcessGenerationResult::default();
}

// Sorting based on sort_by_cached_key from std lib
Expand Down Expand Up @@ -316,6 +310,7 @@ impl GcQueue {
// GC the tasks
let mut content_dropped_count = 0;
let mut unloaded_count = 0;
let mut already_unloaded_count = 0;
for task in tasks[..tasks_to_collect].iter() {
backend.with_task(*task, |task| {
match task.run_gc(generation, self, backend, turbo_tasks) {
Expand All @@ -327,6 +322,9 @@ impl GcQueue {
GcResult::Unloaded => {
unloaded_count += 1;
}
GcResult::AlreadyUnloaded => {
already_unloaded_count += 1;
}
}
});
}
Expand All @@ -335,6 +333,7 @@ impl GcQueue {
priority: Some(max_priority),
content_dropped_count,
unloaded_count,
already_unloaded_count,
}
}

Expand Down Expand Up @@ -363,11 +362,13 @@ impl GcQueue {
priority,
content_dropped_count,
unloaded_count,
already_unloaded_count,
} = self.process_old_generation(backend, turbo_tasks);

span.record("deactivations_count", deactivations_count);
span.record("content_dropped_count", content_dropped_count);
span.record("unloaded_count", unloaded_count);
span.record("already_unloaded_count", already_unloaded_count);
if let Some(priority) = &priority {
span.record("priority", debug(priority));
} else {
Expand Down
5 changes: 3 additions & 2 deletions crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ pub enum GcResult {
/// from the graph and only makes sense when the task isn't currently
/// active.
Unloaded,
AlreadyUnloaded,
}

pub enum ReadCellError {
Expand Down Expand Up @@ -1754,9 +1755,9 @@ impl Task {
}
TaskMetaStateWriteGuard::Partial(mut state) => {
state.aggregation_node.shrink_to_fit();
GcResult::Unloaded
GcResult::AlreadyUnloaded
}
TaskMetaStateWriteGuard::Unloaded(_) => GcResult::Unloaded,
TaskMetaStateWriteGuard::Unloaded(_) => GcResult::AlreadyUnloaded,
TaskMetaStateWriteGuard::TemporaryFiller => unreachable!(),
}
}
Expand Down

0 comments on commit ee2fb72

Please sign in to comment.