Commit 45c60a38 authored by Luke Sandberg's avatar Luke Sandberg

use a queue and a veqdeque to use a more bfs like traversal which should tend to…

use a queue and a veqdeque to use a more bfs like traversal which should tend to decrease retraversals
parent c8201396
...@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize}; ...@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
use tracing::{Instrument, Span}; use tracing::{Instrument, Span};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
CollectiblesSource, FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, CollectiblesSource, FxIndexMap, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt,
ValueToString, Vc, ValueToString, Vc,
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
...@@ -588,17 +588,20 @@ impl SingleModuleGraph { ...@@ -588,17 +588,20 @@ impl SingleModuleGraph {
&'a SingleModuleGraphNode, &'a SingleModuleGraphNode,
) -> Result<GraphTraversalAction>, ) -> Result<GraphTraversalAction>,
) -> Result<usize> { ) -> Result<usize> {
let mut queue = let mut queue = VecDeque::default();
FxIndexSet::from_iter(entries.into_iter().map(|n| self.get_module(n).unwrap())); let mut queue_set = FxHashSet::default();
for index in &queue { for module in entries {
// We should only ever revisit an entry point if we find another path to it from another let index = self.get_module(module).unwrap();
// entry point, so we don't really care about the return value here. let action = visit(None, self.graph.node_weight(index).unwrap())?;
visit(None, self.graph.node_weight(*index).unwrap())?; if action == GraphTraversalAction::Continue && queue_set.insert(index) {
queue.push_back(index);
}
} }
let mut visit_count = 0; let mut visit_count = 0;
while let Some(index) = queue.pop() { while let Some(index) = queue.pop_front() {
queue_set.remove(&index);
let node = match self.graph.node_weight(index).unwrap() { let node = match self.graph.node_weight(index).unwrap() {
SingleModuleGraphNode::Module(single_module_graph_module_node) => { SingleModuleGraphNode::Module(single_module_graph_module_node) => {
single_module_graph_module_node single_module_graph_module_node
...@@ -616,8 +619,8 @@ impl SingleModuleGraph { ...@@ -616,8 +619,8 @@ impl SingleModuleGraph {
let target_index = edge.target(); let target_index = edge.target();
let target = self.graph.node_weight(edge.target()).unwrap(); let target = self.graph.node_weight(edge.target()).unwrap();
let action = visit(Some((node, refdata)), target)?; let action = visit(Some((node, refdata)), target)?;
if action == GraphTraversalAction::Continue { if action == GraphTraversalAction::Continue && queue_set.insert(target_index) {
queue.insert(target_index); queue.push_back(target_index);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment