Skip to content

Commit 1e8c927

Browse files
committed
print timing
1 parent f2ebb07 commit 1e8c927

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
7373
included_modules = tracing::field::Empty
7474
);
7575

76+
let start = std::time::Instant::now();
77+
7678
let span = span_outer.clone();
7779
async move {
7880
let async_module_info = module_graph.async_module_info().await?;
@@ -99,6 +101,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
99101
let mut entry_modules =
100102
FxHashSet::with_capacity_and_hasher(module_count, Default::default());
101103

104+
let inner_span = tracing::info_span!("collect mergeable modules");
102105
let mergeable = graphs
103106
.iter()
104107
.flat_map(|g| g.iter_nodes())
@@ -113,10 +116,13 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
113116
Ok(None)
114117
})
115118
.try_flat_join()
119+
.instrument(inner_span)
116120
.await?
117121
.into_iter()
118122
.collect::<FxHashSet<_>>();
119123

124+
let inner_span = tracing::info_span!("fixed point traversal").entered();
125+
120126
let mut next_index = 0u32;
121127
let visit_count = module_graph.traverse_edges_fixed_point_with_priority(
122128
entries.iter().map(|e| (*e, 0)),
@@ -197,6 +203,11 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
197203
|_, _| Ok(0),
198204
)?;
199205

206+
drop(inner_span);
207+
let inner_span = tracing::info_span!("chunk group collection").entered();
208+
209+
let after_fixed_point = std::time::Instant::now();
210+
200211
span.record("visit_count", visit_count);
201212

202213
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -313,6 +324,11 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
313324
)?;
314325
}
315326

327+
drop(inner_span);
328+
let inner_span = tracing::info_span!("exposed computation").entered();
329+
330+
let after_chunk_groups = std::time::Instant::now();
331+
316332
// We use list.pop() below, so reverse order using negation
317333
lists_reverse_indices
318334
.sort_by_cached_key(|_, b| b.iter().map(|o| o.entry).min().map(|v| -(v as i64)));
@@ -363,6 +379,8 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
363379
},
364380
)?;
365381

382+
drop(inner_span);
383+
let inner_span = tracing::info_span!("reconciliation").entered();
366384
while let Some((_, common_occurrences)) = lists_reverse_indices.pop() {
367385
if common_occurrences.len() < 2 {
368386
// Module exists only in one list, no need to split
@@ -485,10 +503,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
485503
lists.push(after_list.clone());
486504
for (i, &m) in after_list.iter().enumerate() {
487505
let Some(occurrences) = lists_reverse_indices.get_mut(&m) else {
488-
bail!(
489-
"Couldn't find module in list {:?}",
490-
m.ident().to_string().await?,
491-
);
506+
bail!("Couldn't find module in reverse list");
492507
};
493508

494509
let removed = occurrences.swap_remove(&ListOccurrence {
@@ -509,6 +524,10 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
509524
// Dedupe the lists
510525
let lists = lists.into_iter().collect::<FxHashSet<_>>();
511526

527+
let after_reconcile = std::time::Instant::now();
528+
529+
drop(inner_span);
530+
let inner_span = tracing::info_span!("merging");
512531
// Call MergeableModule impl to merge the modules.
513532
let result = lists
514533
.into_iter()
@@ -570,6 +589,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
570589
)))
571590
})
572591
.try_join()
592+
.instrument(inner_span)
573593
.await?;
574594

575595
#[allow(clippy::type_complexity)]
@@ -593,6 +613,23 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
593613
span.record("merged_groups", replacements.len());
594614
span.record("included_modules", included.len());
595615

616+
let end = std::time::Instant::now();
617+
618+
println!(
619+
"Merged modules groups in {} ms (fixed_point: {}, chunk_groups: {}, reconcile: {}), \
620+
{} modules, {} visits",
621+
after_fixed_point.duration_since(start).as_millis(),
622+
after_chunk_groups
623+
.duration_since(after_fixed_point)
624+
.as_millis(),
625+
after_reconcile
626+
.duration_since(after_chunk_groups)
627+
.as_millis(),
628+
end.duration_since(start).as_millis(),
629+
module_count,
630+
visit_count
631+
);
632+
596633
Ok(MergedModuleInfo {
597634
replacements,
598635
replacements_to_original,

0 commit comments

Comments
 (0)