From cb0f969b623a7e12a0d8166c9a498e17a8b5a3c4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Oct 2025 16:57:24 +1000 Subject: [PATCH 1/2] Avoid getting `dep_dep_node` unnecessarily. It's gotten on a hot path but only for use within `debug!`. --- compiler/rustc_query_system/src/dep_graph/graph.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 7e258aaa54f7..eafb38bd25bb 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -876,14 +876,19 @@ fn try_mark_parent_green>( frame: Option<&MarkFrame<'_>>, ) -> Option<()> { let dep_dep_node_color = self.colors.get(parent_dep_node_index); - let dep_dep_node = &self.previous.index_to_node(parent_dep_node_index); + + let get_dep_dep_node = || self.previous.index_to_node(parent_dep_node_index); match dep_dep_node_color { Some(DepNodeColor::Green(_)) => { // This dependency has been marked as green before, we are // still fine and can continue with checking the other // dependencies. - debug!("dependency {dep_dep_node:?} was immediately green"); + // + // This path is extremely hot. We don't want to get the + // `dep_dep_node` unless it's necessary. Hence the + // `get_dep_dep_node` closure. + debug!("dependency {:?} was immediately green", get_dep_dep_node()); return Some(()); } Some(DepNodeColor::Red) => { @@ -891,12 +896,14 @@ fn try_mark_parent_green>( // compared to the previous compilation session. We cannot // mark the DepNode as green and also don't need to bother // with checking any of the other dependencies. - debug!("dependency {dep_dep_node:?} was immediately red"); + debug!("dependency {:?} was immediately red", get_dep_dep_node()); return None; } None => {} } + let dep_dep_node = &get_dep_dep_node(); + // We don't know the state of this dependency. If it isn't // an eval_always node, let's try to mark it green recursively. if !qcx.dep_context().is_eval_always(dep_dep_node.kind) { From 3a287e6034e1339198908cd7253fa414447c97d3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Oct 2025 16:58:03 +1000 Subject: [PATCH 2/2] Remove some unnecessary locals. They both have a single use. (They can't be united, though, because `self.colors` might change between the two `get` calls.) --- compiler/rustc_query_system/src/dep_graph/graph.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index eafb38bd25bb..5e62dab0722c 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -875,11 +875,9 @@ fn try_mark_parent_green>( parent_dep_node_index: SerializedDepNodeIndex, frame: Option<&MarkFrame<'_>>, ) -> Option<()> { - let dep_dep_node_color = self.colors.get(parent_dep_node_index); - let get_dep_dep_node = || self.previous.index_to_node(parent_dep_node_index); - match dep_dep_node_color { + match self.colors.get(parent_dep_node_index) { Some(DepNodeColor::Green(_)) => { // This dependency has been marked as green before, we are // still fine and can continue with checking the other @@ -929,9 +927,7 @@ fn try_mark_parent_green>( return None; } - let dep_dep_node_color = self.colors.get(parent_dep_node_index); - - match dep_dep_node_color { + match self.colors.get(parent_dep_node_index) { Some(DepNodeColor::Green(_)) => { debug!("managed to FORCE dependency {dep_dep_node:?} to green"); return Some(());