Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance of the graph aggregation #8686

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/turbo-tasks-memory/src/aggregation/followers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub fn on_added<C: AggregationContext>(
};
let followers_len = aggregating.followers.len();
let optimize = (!already_optimizing_for_node
&& followers_len > MAX_FOLLOWERS
&& (followers_len - MAX_FOLLOWERS).count_ones() == 1)
&& followers_len >= MAX_FOLLOWERS
&& followers_len.count_ones() == 1)
.then(|| {
aggregating
.followers
Expand Down
34 changes: 18 additions & 16 deletions crates/turbo-tasks-memory/src/aggregation/increase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
balance_queue::BalanceQueue, AggegatingNode, AggregationContext, AggregationNode,
AggregationNodeGuard, PreparedInternalOperation, PreparedOperation, StackVec,
};
pub(super) const LEAF_NUMBER: u32 = 64;
pub(super) const LEAF_NUMBER: u32 = 16;

#[derive(Debug)]
pub enum IncreaseReason {
Expand Down Expand Up @@ -179,21 +179,23 @@ impl<C: AggregationContext> PreparedInternalOperation<C>
uppers,
reason,
} => {
let mut need_to_run = true;
while need_to_run {
need_to_run = false;
let mut max = 0;
for upper_id in &uppers {
let upper = ctx.node(upper_id);
let aggregation_number = upper.aggregation_number();
if aggregation_number != u32::MAX {
if aggregation_number > max {
max = aggregation_number;
}
if aggregation_number == target_aggregation_number {
target_aggregation_number += 1;
if max >= target_aggregation_number {
need_to_run = true;
if target_aggregation_number >= LEAF_NUMBER {
let mut need_to_run = true;
while need_to_run {
need_to_run = false;
let mut max = 0;
for upper_id in &uppers {
let upper = ctx.node(upper_id);
let aggregation_number = upper.aggregation_number();
if aggregation_number != u32::MAX {
if aggregation_number > max {
max = aggregation_number;
}
if aggregation_number == target_aggregation_number {
target_aggregation_number += 1;
if max >= target_aggregation_number {
need_to_run = true;
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/turbo-tasks-memory/src/aggregation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ fn chain() {
let aggregated = aggregation_data(&ctx, &current);
assert_eq!(aggregated.value, 15050);
}
assert_eq!(ctx.additions.load(Ordering::SeqCst), 122);
assert_eq!(ctx.additions.load(Ordering::SeqCst), 182);
ctx.additions.store(0, Ordering::SeqCst);
check_invariants(&ctx, once(current.clone()));

Expand All @@ -609,8 +609,8 @@ fn chain() {
check_invariants(&ctx, once(current.clone()));

leaf.incr(&ctx);
// The change need to propagate through 2 aggregated nodes
assert_eq!(ctx.additions.load(Ordering::SeqCst), 2);
// The change need to propagate through 4 aggregated nodes
assert_eq!(ctx.additions.load(Ordering::SeqCst), 4);
ctx.additions.store(0, Ordering::SeqCst);

{
Expand Down Expand Up @@ -640,7 +640,7 @@ fn chain() {

leaf.incr(&ctx);
// This should be less the 20 to prove that we are reusing trees
assert_eq!(ctx.additions.load(Ordering::SeqCst), 3);
assert_eq!(ctx.additions.load(Ordering::SeqCst), 5);
ctx.additions.store(0, Ordering::SeqCst);

{
Expand Down Expand Up @@ -678,10 +678,10 @@ fn chain_double_connected() {

{
let aggregated = aggregation_data(&ctx, &current);
assert_eq!(aggregated.value, 13188);
assert_eq!(aggregated.value, 20017);
}
check_invariants(&ctx, once(current.clone()));
assert_eq!(ctx.additions.load(Ordering::SeqCst), 285);
assert_eq!(ctx.additions.load(Ordering::SeqCst), 643);
ctx.additions.store(0, Ordering::SeqCst);

print(&ctx, &current, true);
Expand Down
7 changes: 3 additions & 4 deletions crates/turbo-tasks-memory/src/aggregation/uppers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ pub fn on_added<C: AggregationContext>(
) -> usize {
let uppers = node.uppers();
let uppers_len = uppers.len();
let optimize = (!already_optimizing_for_upper
&& uppers_len > MAX_UPPERS
&& (uppers_len - MAX_UPPERS).count_ones() == 1)
.then(|| (true, uppers.iter().cloned().collect::<StackVec<_>>()));
let optimize =
(!already_optimizing_for_upper && uppers_len >= MAX_UPPERS && uppers_len.count_ones() == 1)
.then(|| (true, uppers.iter().cloned().collect::<StackVec<_>>()));
let (add_change, followers) = match &mut *node {
AggregationNode::Leaf { .. } => {
let add_change = node.get_add_change();
Expand Down
Loading