@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
3
3
use rspack_collections:: IdentifierMap ;
4
4
use rustc_hash:: FxHashSet as HashSet ;
5
+ use tracing:: instrument;
5
6
6
7
use super :: new_code_splitter:: { CacheableChunkItem , ChunkDesc , EntryChunkDesc } ;
7
8
use crate :: Compilation ;
@@ -78,6 +79,7 @@ impl AvailableModules {
78
79
}
79
80
}
80
81
82
+ #[ instrument( skip_all) ]
81
83
#[ allow( unused_variables) ]
82
84
pub fn remove_available_modules (
83
85
compilation : & Compilation ,
@@ -126,11 +128,13 @@ pub fn remove_available_modules(
126
128
continue ;
127
129
}
128
130
let res = res. into_owned ( ) ;
129
- * curr = res. clone ( ) ;
130
- res
131
+ * curr = res;
132
+ curr
131
133
} else {
132
- available_modules[ chunk_index] = Some ( parent_available_modules. clone ( ) ) ;
133
- parent_available_modules
134
+ available_modules[ chunk_index] = Some ( parent_available_modules) ;
135
+ available_modules[ chunk_index]
136
+ . as_ref ( )
137
+ . expect ( "should have available modules" )
134
138
} ;
135
139
136
140
// we have incomings that are not calculated, wait till we calculated
@@ -175,14 +179,18 @@ pub fn remove_available_modules(
175
179
}
176
180
177
181
let module_graph = compilation. get_module_graph ( ) ;
182
+ let mut removed = HashSet :: default ( ) ;
183
+ let mut disconnect_children = HashSet :: default ( ) ;
184
+
178
185
for ( chunk_index, available) in available_modules. iter ( ) . enumerate ( ) {
186
+ removed. clear ( ) ;
187
+ disconnect_children. clear ( ) ;
188
+
179
189
let chunk = & mut chunks[ chunk_index] . 1 . chunk_desc ;
180
190
let Some ( available) = available else {
181
191
continue ;
182
192
} ;
183
193
184
- let mut removed = HashSet :: default ( ) ;
185
-
186
194
chunk. chunk_modules_mut ( ) . retain ( |module_identifier| {
187
195
let module = {
188
196
#[ cfg( debug_assertions) ]
@@ -207,29 +215,30 @@ pub fn remove_available_modules(
207
215
!in_parent
208
216
} ) ;
209
217
218
+ if removed. is_empty ( ) {
219
+ continue ;
220
+ }
221
+
210
222
let chunk = & chunks[ chunk_index] . 1 . chunk_desc ;
211
223
let outgoings = chunk. outgoings ( ) ;
212
- for removed_block_id in & removed {
213
- let mut disconnect_children = HashSet :: default ( ) ;
214
-
215
- chunk_children[ chunk_index] . iter ( ) . for_each ( |child| {
216
- let child_chunk = & chunks[ * child] . 1 . chunk_desc ;
217
-
218
- // if all incomings from current chunk are removed, we can remove this child
219
- if child_chunk. incomings ( ) . iter ( ) . all ( |incoming| {
220
- // if all incomings are not from current chunk, we disconnect them
221
- !removed. contains ( incoming) && !outgoings. contains ( incoming)
222
- } ) {
223
- disconnect_children. insert ( * child) ;
224
- }
225
- } ) ;
226
224
227
- if !disconnect_children . is_empty ( ) {
228
- chunk_children [ chunk_index ] . retain ( |child| !disconnect_children . contains ( child ) ) ;
225
+ chunk_children [ chunk_index ] . iter ( ) . for_each ( |child| {
226
+ let child_chunk = & chunks [ * child ] . 1 . chunk_desc ;
229
227
230
- for dead_child in disconnect_children {
231
- chunk_parents[ dead_child] . retain ( |parent| * parent != chunk_index) ;
232
- }
228
+ // if all incomings from current chunk are removed, we can remove this child
229
+ if child_chunk. incomings ( ) . iter ( ) . all ( |incoming| {
230
+ // if all incomings are not from current chunk, we disconnect them
231
+ !removed. contains ( incoming) && !outgoings. contains ( incoming)
232
+ } ) {
233
+ disconnect_children. insert ( * child) ;
234
+ }
235
+ } ) ;
236
+
237
+ if !disconnect_children. is_empty ( ) {
238
+ chunk_children[ chunk_index] . retain ( |child| !disconnect_children. contains ( child) ) ;
239
+
240
+ for dead_child in & disconnect_children {
241
+ chunk_parents[ * dead_child] . retain ( |parent| * parent != chunk_index) ;
233
242
}
234
243
}
235
244
}
0 commit comments