@@ -9,7 +9,6 @@ use std::{
9
9
} ;
10
10
11
11
use dashmap:: DashSet ;
12
- use futures:: future:: join_all;
13
12
use indexmap:: { IndexMap , IndexSet } ;
14
13
use itertools:: Itertools ;
15
14
use rayon:: prelude:: * ;
@@ -2252,23 +2251,50 @@ impl Compilation {
2252
2251
. iter ( )
2253
2252
. filter ( |key| !unordered_runtime_chunks. contains ( key) )
2254
2253
. collect ( ) ;
2254
+
2255
2255
// create hash for runtime modules in other chunks
2256
- for chunk in & other_chunks {
2257
- for runtime_module_identifier in self . chunk_graph . get_chunk_runtime_modules_iterable ( chunk) {
2258
- let runtime_module = & self . runtime_modules [ runtime_module_identifier] ;
2259
- let digest = runtime_module. get_runtime_hash ( self , None ) . await ?;
2260
- self
2261
- . runtime_modules_hash
2262
- . insert ( * runtime_module_identifier, digest) ;
2263
- }
2256
+ let other_chunk_runtime_module_hashes = rspack_futures:: scope :: < _ , Result < _ > > ( |token| {
2257
+ other_chunks
2258
+ . iter ( )
2259
+ . flat_map ( |chunk| self . chunk_graph . get_chunk_runtime_modules_iterable ( chunk) )
2260
+ . for_each ( |runtime_module_identifier| {
2261
+ let s = unsafe { token. used ( ( & self , runtime_module_identifier) ) } ;
2262
+ s. spawn ( |( compilation, runtime_module_identifier) | async {
2263
+ let runtime_module = & compilation. runtime_modules [ runtime_module_identifier] ;
2264
+ let digest = runtime_module. get_runtime_hash ( compilation, None ) . await ?;
2265
+ Ok ( ( * runtime_module_identifier, digest) )
2266
+ } ) ;
2267
+ } )
2268
+ } )
2269
+ . await
2270
+ . into_iter ( )
2271
+ . map ( |res| res. to_rspack_result ( ) )
2272
+ . collect :: < Result < Vec < _ > > > ( ) ?;
2273
+
2274
+ for res in other_chunk_runtime_module_hashes {
2275
+ let ( runtime_module_identifier, digest) = res?;
2276
+ self
2277
+ . runtime_modules_hash
2278
+ . insert ( runtime_module_identifier, digest) ;
2264
2279
}
2280
+
2265
2281
// create hash for other chunks
2266
- let other_chunks_hash_results: Vec < Result < ( ChunkUkey , ChunkHashResult ) > > =
2267
- join_all ( other_chunks. into_iter ( ) . map ( |chunk| async {
2268
- let hash_result = self . process_chunk_hash ( * chunk, & plugin_driver) . await ?;
2269
- Ok ( ( * chunk, hash_result) )
2270
- } ) )
2271
- . await ;
2282
+ let other_chunks_hash_results = rspack_futures:: scope :: < _ , Result < _ > > ( |token| {
2283
+ for chunk in other_chunks {
2284
+ let s = unsafe { token. used ( ( & self , chunk, & plugin_driver) ) } ;
2285
+ s. spawn ( |( compilation, chunk, plugin_driver) | async {
2286
+ let hash_result = compilation
2287
+ . process_chunk_hash ( * chunk, plugin_driver)
2288
+ . await ?;
2289
+ Ok ( ( * chunk, hash_result) )
2290
+ } ) ;
2291
+ }
2292
+ } )
2293
+ . await
2294
+ . into_iter ( )
2295
+ . map ( |res| res. to_rspack_result ( ) )
2296
+ . collect :: < Result < Vec < _ > > > ( ) ?;
2297
+
2272
2298
try_process_chunk_hash_results ( self , other_chunks_hash_results) ?;
2273
2299
logger. time_end ( start) ;
2274
2300
@@ -2379,16 +2405,29 @@ impl Compilation {
2379
2405
// Therefore, create hashes one by one in sequence.
2380
2406
let start = logger. time ( "hashing: hash runtime chunks" ) ;
2381
2407
for runtime_chunk_ukey in runtime_chunks {
2382
- for runtime_module_identifier in self
2383
- . chunk_graph
2384
- . get_chunk_runtime_modules_iterable ( & runtime_chunk_ukey)
2385
- {
2386
- let runtime_module = & self . runtime_modules [ runtime_module_identifier] ;
2387
- let digest = runtime_module. get_runtime_hash ( self , None ) . await ?;
2408
+ let runtime_module_hashes = rspack_futures:: scope :: < _ , Result < _ > > ( |token| {
2388
2409
self
2389
- . runtime_modules_hash
2390
- . insert ( * runtime_module_identifier, digest) ;
2410
+ . chunk_graph
2411
+ . get_chunk_runtime_modules_iterable ( & runtime_chunk_ukey)
2412
+ . for_each ( |runtime_module_identifier| {
2413
+ let s = unsafe { token. used ( ( & self , runtime_module_identifier) ) } ;
2414
+ s. spawn ( |( compilation, runtime_module_identifier) | async {
2415
+ let runtime_module = & compilation. runtime_modules [ runtime_module_identifier] ;
2416
+ let digest = runtime_module. get_runtime_hash ( compilation, None ) . await ?;
2417
+ Ok ( ( * runtime_module_identifier, digest) )
2418
+ } ) ;
2419
+ } )
2420
+ } )
2421
+ . await
2422
+ . into_iter ( )
2423
+ . map ( |res| res. to_rspack_result ( ) )
2424
+ . collect :: < Result < Vec < _ > > > ( ) ?;
2425
+
2426
+ for res in runtime_module_hashes {
2427
+ let ( mid, digest) = res?;
2428
+ self . runtime_modules_hash . insert ( mid, digest) ;
2391
2429
}
2430
+
2392
2431
let chunk_hash_result = self
2393
2432
. process_chunk_hash ( runtime_chunk_ukey, & plugin_driver)
2394
2433
. await ?;
0 commit comments