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