@@ -1295,6 +1295,9 @@ impl Module for ConcatenatedModule {
1295
1295
compilation : & Compilation ,
1296
1296
generation_runtime : Option < & RuntimeSpec > ,
1297
1297
) -> Result < RspackHashDigest > {
1298
+ use rayon:: prelude:: * ;
1299
+ use tokio:: runtime:: Handle ;
1300
+
1298
1301
let mut hasher = RspackHash :: from ( & compilation. options . output ) ;
1299
1302
let runtime = if let Some ( self_runtime) = & self . runtime
1300
1303
&& let Some ( generation_runtime) = generation_runtime
@@ -1309,32 +1312,47 @@ impl Module for ConcatenatedModule {
1309
1312
generation_runtime. map ( Cow :: Borrowed )
1310
1313
} ;
1311
1314
let runtime = runtime. as_deref ( ) ;
1312
- for info in self . create_concatenation_list (
1315
+ let list = self . create_concatenation_list (
1313
1316
self . root_module_ctxt . id ,
1314
1317
self . modules . iter ( ) . map ( |item| item. id ) . collect ( ) ,
1315
1318
runtime,
1316
1319
& compilation. get_module_graph ( ) ,
1317
- ) {
1318
- match info {
1319
- ConcatenationEntry :: Concatenated ( e) => {
1320
- compilation
1321
- . get_module_graph ( )
1322
- . module_by_identifier ( & e. module )
1323
- . expect ( "should have module" )
1324
- . get_runtime_hash ( compilation, generation_runtime)
1325
- . await ?
1326
- . encoded ( )
1327
- . dyn_hash ( & mut hasher) ;
1328
- }
1329
- ConcatenationEntry :: External ( e) => {
1330
- ChunkGraph :: get_module_id (
1331
- & compilation. module_ids_artifact ,
1332
- e. module ( & compilation. get_module_graph ( ) ) ,
1333
- )
1334
- . dyn_hash ( & mut hasher) ;
1335
- }
1336
- } ;
1337
- }
1320
+ ) ;
1321
+ let handle = Handle :: current ( ) ;
1322
+
1323
+ let to_hash = |info : & _ | match info {
1324
+ ConcatenationEntry :: Concatenated ( e) => {
1325
+ let mg = compilation. get_module_graph ( ) ;
1326
+ let fut = mg
1327
+ . module_by_identifier ( & e. module )
1328
+ . expect ( "should have module" )
1329
+ . get_runtime_hash ( compilation, generation_runtime) ;
1330
+ let result = tokio:: task:: block_in_place ( || handle. block_on ( fut) ) ;
1331
+ result. map ( |digest| Box :: new ( digest) as Box < dyn DynHash + Send > )
1332
+ }
1333
+ ConcatenationEntry :: External ( e) => {
1334
+ let maybe_module_id = ChunkGraph :: get_module_id (
1335
+ & compilation. module_ids_artifact ,
1336
+ e. module ( & compilation. get_module_graph ( ) ) ,
1337
+ )
1338
+ . cloned ( ) ;
1339
+ Ok ( Box :: new ( maybe_module_id) as Box < _ > )
1340
+ }
1341
+ } ;
1342
+
1343
+ if list. len ( ) > 2 {
1344
+ let list = list. par_iter ( ) . map ( to_hash) . collect :: < Result < Vec < _ > > > ( ) ?;
1345
+
1346
+ for digest in list {
1347
+ digest. dyn_hash ( & mut hasher) ;
1348
+ }
1349
+ } else {
1350
+ for digest in list. iter ( ) . map ( to_hash) {
1351
+ let digest = digest?;
1352
+ digest. dyn_hash ( & mut hasher) ;
1353
+ }
1354
+ } ;
1355
+
1338
1356
module_update_hash ( self , & mut hasher, compilation, generation_runtime) ;
1339
1357
Ok ( hasher. digest ( & compilation. options . output . hash_digest ) )
1340
1358
}
0 commit comments