Unverified Commit 6f6ea204 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Simplify aggregation update queue control flow (#100146)

Now that we are no longer suspending we can simplify control flow and
implementation of the AggregationUpdateQueue

* drop an unneeded `Clone` derive
* process batch tasks via loops instead of `pop` + `push_front`
* when we run out of optimization quota just immediately tag everything
instead of popping each task and checking the quote again
* simplify the public apis
parent 179eba81
...@@ -302,7 +302,7 @@ impl TurboTasksBackend { ...@@ -302,7 +302,7 @@ impl TurboTasksBackend {
let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector); let mut ctx = ExecuteContext::new_for_gc(self, turbo_tasks, phase, &noop_collector);
let mut queue = AggregationUpdateQueue::new(); let mut queue = AggregationUpdateQueue::new();
queue.extend_balance_edges(deferred, &mut ctx); queue.extend_balance_edges(deferred, &mut ctx);
while !queue.process(&mut ctx) {} queue.execute(&mut ctx);
} }
// Collect all active roots // Collect all active roots
......
...@@ -336,22 +336,17 @@ fn cleanup_old_edges_inner( ...@@ -336,22 +336,17 @@ fn cleanup_old_edges_inner(
} }
} }
while !stop_when_only_rebalance_remains || !queue.only_rebalance_remains() { if stop_when_only_rebalance_remains {
if queue.process(ctx) { // Edge removal is done; hand the rebalance back to the caller. Any
// other pending work would be dropped here, so `execute_until_rebalance`
// asserts that nothing else is left.
let balance_edges = queue.execute_until_rebalance(ctx);
return (Default::default(), Some(DeferredCleanup { balance_edges }));
}
queue.execute(ctx);
#[cfg(feature = "trace_aggregation_update_stats")] #[cfg(feature = "trace_aggregation_update_stats")]
let stats = take(&mut queue.stats); let stats = take(&mut queue.stats);
#[cfg(not(feature = "trace_aggregation_update_stats"))] #[cfg(not(feature = "trace_aggregation_update_stats"))]
let stats = (); let stats = ();
return (stats, None); (stats, None)
}
}
// Edge removal is done; hand the rebalance back to the caller. Any
// other pending work would be dropped here, so `only_rebalance_remains`
// asserts that nothing else is left.
(
Default::default(),
Some(DeferredCleanup {
balance_edges: queue.take_deferred_balance_edges().collect(),
}),
)
} }
...@@ -12,9 +12,6 @@ use crate::backend::{ ...@@ -12,9 +12,6 @@ use crate::backend::{
TaskDataCategory, operation::ExecuteContext, storage_schema::TaskStorageAccessors, TaskDataCategory, operation::ExecuteContext, storage_schema::TaskStorageAccessors,
}; };
/// The maximum number of leaf distance updates processed in one step.
const MAX_COUNT_BEFORE_YIELD: usize = 1000;
/// We avoid incrementing the leaf distance by 1 each time to avoid frequent updates. /// We avoid incrementing the leaf distance by 1 each time to avoid frequent updates.
/// Instead we use a buffer zone that shrinks as the leaf distance increases. /// Instead we use a buffer zone that shrinks as the leaf distance increases.
/// This constant defines the size of that buffer zone at leaf distance 0. /// This constant defines the size of that buffer zone at leaf distance 0.
...@@ -52,10 +49,6 @@ impl LeafDistanceUpdateQueue { ...@@ -52,10 +49,6 @@ impl LeafDistanceUpdateQueue {
Self::default() Self::default()
} }
pub fn is_empty(&self) -> bool {
self.queue.is_empty()
}
pub fn push( pub fn push(
&mut self, &mut self,
task_id: TaskId, task_id: TaskId,
...@@ -84,11 +77,9 @@ impl LeafDistanceUpdateQueue { ...@@ -84,11 +77,9 @@ impl LeafDistanceUpdateQueue {
}; };
} }
/// Executes a single step of the queue. Returns true, when the queue is empty. /// Executes all jobs in the queue.
pub fn process(&mut self, ctx: &mut ExecuteContext<'_>) -> bool { pub fn execute(&mut self, ctx: &mut ExecuteContext<'_>) {
let mut remaining = MAX_COUNT_BEFORE_YIELD; while let Some((Reverse(queue_dependencies_distance), task_id)) = self.queue.pop() {
while remaining > 0 {
if let Some((Reverse(queue_dependencies_distance), task_id)) = self.queue.pop() {
let &mut LeafDistanceUpdate { let &mut LeafDistanceUpdate {
dependencies_distance, dependencies_distance,
dependencies_max_distance_in_buffer, dependencies_max_distance_in_buffer,
...@@ -111,12 +102,7 @@ impl LeafDistanceUpdateQueue { ...@@ -111,12 +102,7 @@ impl LeafDistanceUpdateQueue {
dependencies_distance, dependencies_distance,
dependencies_max_distance_in_buffer, dependencies_max_distance_in_buffer,
); );
remaining -= 1;
} else {
return true;
}
} }
false
} }
fn update_leaf_distance( fn update_leaf_distance(
...@@ -168,11 +154,4 @@ impl LeafDistanceUpdateQueue { ...@@ -168,11 +154,4 @@ impl LeafDistanceUpdateQueue {
} }
task.set_leaf_distance(leaf_distance); task.set_leaf_distance(leaf_distance);
} }
pub fn execute(&mut self, ctx: &mut ExecuteContext<'_>) {
if self.is_empty() {
return;
}
while !self.process(ctx) {}
}
} }
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