From 764a4a38ba12e938f8af89ec7e18cd8488c17b26 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 11 Oct 2026 05:01:53 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20liveness=20dataf?= =?UTF-8?q?low=20iteration=20order=20and=20reduce=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- compiler/optimizer/src/analysis/liveness.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/optimizer/src/analysis/liveness.rs b/compiler/optimizer/src/analysis/liveness.rs index bbfc72eb..e17e4aab 100644 --- a/compiler/optimizer/src/analysis/liveness.rs +++ b/compiler/optimizer/src/analysis/liveness.rs @@ -66,7 +66,9 @@ impl LivenessAnalysis { while changed { changed = false; - for block in &func.blocks { + // OPTIMIZATION: Liveness is a backward dataflow analysis. Iterating + // through blocks in reverse order speeds up convergence significantly. + for block in func.blocks.iter().rev() { let block_id = block.id; // LiveOut = union of LiveIn(succs) @@ -89,14 +91,16 @@ impl LivenessAnalysis { if let Some(old_in) = live_in.get_mut(&block_id) { if old_in.len() != new_in.len() { - *old_in = new_in.clone(); + // OPTIMIZATION: Reuse existing HashSet capacity to avoid allocations in hot loop. + old_in.clone_from(&new_in); changed = true; } } if let Some(old_out) = live_out.get_mut(&block_id) { if old_out.len() != new_out.len() { - *old_out = new_out.clone(); + // OPTIMIZATION: Reuse existing HashSet capacity to avoid allocations in hot loop. + old_out.clone_from(&new_out); changed = true; } }