@@ -6,6 +6,7 @@ use std::{
6
6
} ;
7
7
8
8
use anyhow:: { bail, Context , Result } ;
9
+ use tracing:: Instrument ;
9
10
use turbo_rcstr:: RcStr ;
10
11
use turbo_tasks:: {
11
12
apply_effects, ReadConsistency , ResolvedVc , TransientInstance , TryJoinIterExt , TurboTasks ,
@@ -134,7 +135,9 @@ impl TurbopackBuildBuilder {
134
135
// Await the result to propagate any errors.
135
136
build_result_op. read_strongly_consistent ( ) . await ?;
136
137
137
- apply_effects ( build_result_op) . await ?;
138
+ apply_effects ( build_result_op)
139
+ . instrument ( tracing:: info_span!( "apply effects" ) )
140
+ . await ?;
138
141
139
142
let issue_reporter: Vc < Box < dyn IssueReporter > > =
140
143
Vc :: upcast ( ConsoleUi :: new ( TransientInstance :: new ( LogOptions {
@@ -300,41 +303,75 @@ async fn build_internal(
300
303
301
304
let origin = PlainResolveOrigin :: new ( asset_context, project_fs. root ( ) . join ( "_" . into ( ) ) ) ;
302
305
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 ?;
323
330
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 ?;
325
338
326
339
let entry_chunk_groups = entries
327
340
. 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(
338
375
build_output_root
339
376
. join(
340
377
ecmascript
@@ -347,58 +384,46 @@ async fn build_internal(
347
384
. into( ) ,
348
385
)
349
386
. 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
+ ] ) ,
357
396
}
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
390
407
} )
391
408
. try_join ( )
392
409
. await ?;
393
410
394
411
let mut chunks: HashSet < ResolvedVc < Box < dyn OutputAsset > > > = HashSet :: new ( ) ;
395
412
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
+ ) ;
397
418
}
398
419
399
420
chunks
400
421
. 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
+ } )
402
427
. try_join ( )
403
428
. await ?;
404
429
0 commit comments