Skip to content

Commit

Permalink
perf: limit the number of hoisting candidates to 100.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Nov 22, 2024
1 parent ffe215a commit 6ab8aef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/src/compiler/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ impl IR {
/// - Add a node to the result vector only if its parent does not depend on
/// the same variable. This avoids hoisting sub-expressions that are part
/// of a larger expression also eligible to be hoisted from the same loop.
/// - The number of candidates is limited to 100. Too many candidates produce
/// very deep IR trees with many nested `with` statement, which often
/// results in code that is slower than the original one.
///
/// The final result is a list of loop-invariant expressions and the loops
/// they can be hoisted from, ensuring optimal code motion without redundant
Expand Down Expand Up @@ -1139,6 +1142,11 @@ impl IR {
if let Some(inner_loop) = scopes.next() {
result.push((current_expr_id, inner_loop));
}
// Limit the number of candidates to a reasonable
// number.
if result.len() > 100 {
return result;
}
}
}
}
Expand Down

0 comments on commit 6ab8aef

Please sign in to comment.