From 65ccc41aa1a4b8cf54fd3e34f094eb791af79134 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 21 Apr 2026 18:36:41 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20Tarjan's=20DFS?= =?UTF-8?q?=20in=20invalidation=20detector=20by=20eliminating=20redundant?= =?UTF-8?q?=20PathBuf=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By switching to owned PathBuf instances purely for insertion, and utilizing &Path for all subsequent read/write `HashMap` interactions, we prevent repeated heap allocations taking place during every node evaluation within O(V+E) traversal. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- crates/flow/src/incremental/invalidation.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/flow/src/incremental/invalidation.rs b/crates/flow/src/incremental/invalidation.rs index da9ac9c..b2e1e92 100644 --- a/crates/flow/src/incremental/invalidation.rs +++ b/crates/flow/src/incremental/invalidation.rs @@ -342,11 +342,13 @@ impl InvalidationDetector { fn tarjan_dfs(&self, v: &Path, state: &mut TarjanState, sccs: &mut Vec>) { // Initialize node let index = state.index_counter; - state.indices.insert(v.to_path_buf(), index); - state.lowlinks.insert(v.to_path_buf(), index); + + let v_owned = v.to_path_buf(); + state.indices.insert(v_owned.clone(), index); + state.lowlinks.insert(v_owned.clone(), index); state.index_counter += 1; - state.stack.push(v.to_path_buf()); - state.on_stack.insert(v.to_path_buf()); + state.stack.push(v_owned.clone()); + state.on_stack.insert(v_owned); // Visit all successors (dependencies) let dependencies = self.graph.get_dependencies(v); @@ -358,19 +360,19 @@ impl InvalidationDetector { // Update lowlink let w_lowlink = *state.lowlinks.get(dep).unwrap(); - let v_lowlink = state.lowlinks.get_mut(&v.to_path_buf()).unwrap(); + let v_lowlink = state.lowlinks.get_mut(v).unwrap(); *v_lowlink = (*v_lowlink).min(w_lowlink); } else if state.on_stack.contains(dep) { // Successor is on stack (part of current SCC) let w_index = *state.indices.get(dep).unwrap(); - let v_lowlink = state.lowlinks.get_mut(&v.to_path_buf()).unwrap(); + let v_lowlink = state.lowlinks.get_mut(v).unwrap(); *v_lowlink = (*v_lowlink).min(w_index); } } // If v is a root node, pop the stack to create an SCC - let v_index = *state.indices.get(&v.to_path_buf()).unwrap(); - let v_lowlink = *state.lowlinks.get(&v.to_path_buf()).unwrap(); + let v_index = *state.indices.get(v).unwrap(); + let v_lowlink = *state.lowlinks.get(v).unwrap(); if v_lowlink == v_index { let mut scc = Vec::new();