Skip to content

Commit 3e86752

Browse files
committed
Turbopack: more traces
1 parent 3813b2c commit 3e86752

File tree

4 files changed

+102
-74
lines changed

4 files changed

+102
-74
lines changed

Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mime = { workspace = true }
4242
owo-colors = { workspace = true }
4343
serde = { workspace = true }
4444
tokio = { workspace = true, features = ["full"] }
45+
tracing = { workspace = true }
4546
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
4647
turbo-rcstr = { workspace = true }
4748
turbo-tasks = { workspace = true }

turbopack/crates/turbopack-cli/src/build/mod.rs

+98-73
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
};
77

88
use anyhow::{bail, Context, Result};
9+
use tracing::Instrument;
910
use turbo_rcstr::RcStr;
1011
use turbo_tasks::{
1112
apply_effects, ReadConsistency, ResolvedVc, TransientInstance, TryJoinIterExt, TurboTasks,
@@ -134,7 +135,9 @@ impl TurbopackBuildBuilder {
134135
// Await the result to propagate any errors.
135136
build_result_op.read_strongly_consistent().await?;
136137

137-
apply_effects(build_result_op).await?;
138+
apply_effects(build_result_op)
139+
.instrument(tracing::info_span!("apply effects"))
140+
.await?;
138141

139142
let issue_reporter: Vc<Box<dyn IssueReporter>> =
140143
Vc::upcast(ConsoleUi::new(TransientInstance::new(LogOptions {
@@ -300,41 +303,75 @@ async fn build_internal(
300303

301304
let origin = PlainResolveOrigin::new(asset_context, project_fs.root().join("_".into()));
302305
let project_dir = &project_dir;
303-
let entries = entry_requests
304-
.into_iter()
305-
.map(|request_vc| async move {
306-
let ty = Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined));
307-
let request = request_vc.await?;
308-
origin
309-
.resolve_asset(request_vc, origin.resolve_options(ty.clone()), ty)
310-
.await?
311-
.first_module()
312-
.await?
313-
.with_context(|| {
314-
format!(
315-
"Unable to resolve entry {} from directory {}.",
316-
request.request().unwrap(),
317-
project_dir
318-
)
319-
})
320-
})
321-
.try_join()
322-
.await?;
306+
let entries = async move {
307+
entry_requests
308+
.into_iter()
309+
.map(|request_vc| async move {
310+
let ty = Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined));
311+
let request = request_vc.await?;
312+
origin
313+
.resolve_asset(request_vc, origin.resolve_options(ty.clone()), ty)
314+
.await?
315+
.first_module()
316+
.await?
317+
.with_context(|| {
318+
format!(
319+
"Unable to resolve entry {} from directory {}.",
320+
request.request().unwrap(),
321+
project_dir
322+
)
323+
})
324+
})
325+
.try_join()
326+
.await
327+
}
328+
.instrument(tracing::info_span!("resolve entries"))
329+
.await?;
323330

324-
let module_graph = ModuleGraph::from_modules(Vc::cell(entries.clone()));
331+
let module_graph = async {
332+
ModuleGraph::from_modules(Vc::cell(entries.clone()))
333+
.resolve()
334+
.await
335+
}
336+
.instrument(tracing::info_span!("prepare module graph"))
337+
.await?;
325338

326339
let entry_chunk_groups = entries
327340
.into_iter()
328-
.map(|entry_module| async move {
329-
Ok(
330-
if let Some(ecmascript) =
331-
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry_module).await?
332-
{
333-
match target {
334-
Target::Browser => {
335-
chunking_context
336-
.evaluated_chunk_group(
337-
AssetIdent::from_path(
341+
.map(async |entry_module| {
342+
async move {
343+
Ok(
344+
if let Some(ecmascript) =
345+
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry_module).await?
346+
{
347+
match target {
348+
Target::Browser => {
349+
chunking_context
350+
.evaluated_chunk_group(
351+
AssetIdent::from_path(
352+
build_output_root
353+
.join(
354+
ecmascript
355+
.ident()
356+
.path()
357+
.file_stem()
358+
.await?
359+
.as_deref()
360+
.unwrap()
361+
.into(),
362+
)
363+
.with_extension("entry.js".into()),
364+
),
365+
EvaluatableAssets::one(*ResolvedVc::upcast(ecmascript)),
366+
module_graph,
367+
Value::new(AvailabilityInfo::Root),
368+
)
369+
.await?
370+
.assets
371+
}
372+
Target::Node => ResolvedVc::cell(vec![
373+
chunking_context
374+
.entry_chunk_group(
338375
build_output_root
339376
.join(
340377
ecmascript
@@ -347,58 +384,46 @@ async fn build_internal(
347384
.into(),
348385
)
349386
.with_extension("entry.js".into()),
350-
),
351-
EvaluatableAssets::one(*ResolvedVc::upcast(ecmascript)),
352-
module_graph,
353-
Value::new(AvailabilityInfo::Root),
354-
)
355-
.await?
356-
.assets
387+
*ResolvedVc::upcast(ecmascript),
388+
EvaluatableAssets::one(*ResolvedVc::upcast(ecmascript)),
389+
module_graph,
390+
OutputAssets::empty(),
391+
Value::new(AvailabilityInfo::Root),
392+
)
393+
.await?
394+
.asset,
395+
]),
357396
}
358-
Target::Node => ResolvedVc::cell(vec![
359-
chunking_context
360-
.entry_chunk_group(
361-
build_output_root
362-
.join(
363-
ecmascript
364-
.ident()
365-
.path()
366-
.file_stem()
367-
.await?
368-
.as_deref()
369-
.unwrap()
370-
.into(),
371-
)
372-
.with_extension("entry.js".into()),
373-
*ResolvedVc::upcast(ecmascript),
374-
EvaluatableAssets::one(*ResolvedVc::upcast(ecmascript)),
375-
module_graph,
376-
OutputAssets::empty(),
377-
Value::new(AvailabilityInfo::Root),
378-
)
379-
.await?
380-
.asset,
381-
]),
382-
}
383-
} else {
384-
bail!(
385-
"Entry module is not chunkable, so it can't be used to bootstrap the \
386-
application"
387-
)
388-
},
389-
)
397+
} else {
398+
bail!(
399+
"Entry module is not chunkable, so it can't be used to bootstrap the \
400+
application"
401+
)
402+
},
403+
)
404+
}
405+
.instrument(tracing::info_span!("chunk entry"))
406+
.await
390407
})
391408
.try_join()
392409
.await?;
393410

394411
let mut chunks: HashSet<ResolvedVc<Box<dyn OutputAsset>>> = HashSet::new();
395412
for chunk_group in entry_chunk_groups {
396-
chunks.extend(&*all_assets_from_entries(*chunk_group).await?);
413+
chunks.extend(
414+
&*async move { all_assets_from_entries(*chunk_group).await }
415+
.instrument(tracing::info_span!("list chunks"))
416+
.await?,
417+
);
397418
}
398419

399420
chunks
400421
.iter()
401-
.map(|c| c.content().write(c.ident().path()))
422+
.map(async |c| {
423+
async move { c.content().write(c.ident().path()).resolve().await }
424+
.instrument(tracing::info_span!("build chunk content"))
425+
.await
426+
})
402427
.try_join()
403428
.await?;
404429

turbopack/crates/turbopack-cli/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![feature(min_specialization)]
33
#![feature(arbitrary_self_types)]
44
#![feature(arbitrary_self_types_pointers)]
5+
#![feature(async_closure)]
56

67
pub mod arguments;
78
pub mod build;

0 commit comments

Comments
 (0)