Skip to content

Commit f2ebb07

Browse files
authored
Turbopack: make graph traversal sync (#83891)
We can make them sync now.
1 parent 24326f5 commit f2ebb07

File tree

7 files changed

+480
-508
lines changed

7 files changed

+480
-508
lines changed

crates/next-api/src/webpack_stats.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ where
5858
let asset_reasons = {
5959
let module_graph = module_graph.read_graphs().await?;
6060
let mut edges = vec![];
61-
module_graph
62-
.traverse_all_edges_unordered(|(parent_node, r), current| {
63-
edges.push((
64-
parent_node.module,
65-
RcStr::from(format!("{}: {}", r.chunking_type, r.export)),
66-
current.module,
67-
));
68-
Ok(())
69-
})
70-
.await?;
61+
module_graph.traverse_all_edges_unordered(|(parent_node, r), current| {
62+
edges.push((
63+
parent_node.module,
64+
RcStr::from(format!("{}: {}", r.chunking_type, r.export)),
65+
current.module,
66+
));
67+
Ok(())
68+
})?;
7169

7270
let edges = edges
7371
.into_iter()

turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs

Lines changed: 191 additions & 197 deletions
Large diffs are not rendered by default.

turbopack/crates/turbopack-core/src/module_graph/export_usage.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,35 @@ pub async fn compute_export_usage_info(
1414
) -> Result<Vc<ExportUsageInfo>> {
1515
let mut used_exports = FxHashMap::<_, ModuleExportUsageInfo>::default();
1616
let graph = graph.read_graphs().await?;
17-
graph
18-
.traverse_all_edges_unordered(|(_, ref_data), target| {
19-
let e = used_exports.entry(target.module).or_default();
17+
graph.traverse_all_edges_unordered(|(_, ref_data), target| {
18+
let e = used_exports.entry(target.module).or_default();
2019

21-
e.add(&ref_data.export);
20+
e.add(&ref_data.export);
21+
22+
Ok(())
23+
})?;
2224

23-
Ok(())
24-
})
25-
.await?;
2625
// Compute cycles and select modules to be 'circuit breakers'
2726
// A circuit breaker module will need to eagerly export lazy getters for its exports to break an
2827
// evaluation cycle all other modules can export values after defining them
2928
let mut circuit_breakers = FxHashSet::default();
30-
graph
31-
.traverse_cycles(
32-
|e| e.chunking_type.is_parallel(),
33-
|cycle| {
34-
// To break cycles we need to ensure that no importing module can observe a
35-
// partially populated exports object.
36-
37-
// We could compute this based on the module graph via a DFS from each entry point
38-
// to the cycle. Whatever node is hit first is an entry point to the cycle.
39-
// (scope hoisting does something similar) and then we would only need to
40-
// mark 'entry' modules (basically the targets of back edges in the export graph) as
41-
// circuit breakers. For now we just mark everything on the theory that cycles are
42-
// rare. For vercel-site on 8/22/2025 there were 106 cycles covering 800 modules
43-
// (or 1.2% of all modules). So with this analysis we could potentially drop 80% of
44-
// the cycle breaker modules.
45-
circuit_breakers.extend(cycle.iter().map(|n| n.module));
46-
},
47-
)
48-
.await?;
29+
graph.traverse_cycles(
30+
|e| e.chunking_type.is_parallel(),
31+
|cycle| {
32+
// To break cycles we need to ensure that no importing module can observe a
33+
// partially populated exports object.
34+
35+
// We could compute this based on the module graph via a DFS from each entry point
36+
// to the cycle. Whatever node is hit first is an entry point to the cycle.
37+
// (scope hoisting does something similar) and then we would only need to
38+
// mark 'entry' modules (basically the targets of back edges in the export graph) as
39+
// circuit breakers. For now we just mark everything on the theory that cycles are
40+
// rare. For vercel-site on 8/22/2025 there were 106 cycles covering 800 modules
41+
// (or 1.2% of all modules). So with this analysis we could potentially drop 80% of
42+
// the cycle breaker modules.
43+
circuit_breakers.extend(cycle.iter().map(|n| n.module));
44+
},
45+
)?;
4946

5047
Ok(ExportUsageInfo {
5148
used_exports,

0 commit comments

Comments
 (0)