Skip to content

Commit d192032

Browse files
committed
perf: improve bundle splitting
1 parent cfbe18c commit d192032

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

crates/rspack_plugin_split_chunks/src/plugin/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod max_size;
44
mod min_size;
55
mod module_group;
66

7-
use std::{borrow::Cow, collections::BinaryHeap, fmt::Debug};
7+
use std::{borrow::Cow, fmt::Debug};
88

99
use rspack_collections::UkeyMap;
1010
use rspack_core::{ChunkUkey, Compilation, CompilationOptimizeChunks, Logger, Plugin};

crates/rspack_plugin_split_chunks/src/plugin/module_group.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
cmp::Ordering,
23
collections::{HashMap, hash_map},
34
hash::{BuildHasherDefault, Hash, Hasher},
45
};
@@ -289,20 +290,20 @@ impl SplitChunksPlugin {
289290
&self,
290291
module_group_map: &mut ModuleGroupMap,
291292
) -> (String, ModuleGroup) {
292-
// perf(hyf): I wonder if we could use BinaryHeap to avoid sorting for find_best_module_group call
293293
debug_assert!(!module_group_map.is_empty());
294-
let mut iter: std::collections::hash_map::Iter<String, ModuleGroup> = module_group_map.iter();
295-
let (key, mut best_module_group) = iter.next().expect("at least have one item");
296-
297-
let mut best_entry_key = key;
298-
for (key, each_module_group) in iter {
299-
if compare_entries(best_module_group, each_module_group) < 0f64 {
300-
best_entry_key = key;
301-
best_module_group = each_module_group;
302-
}
303-
}
304294

305-
let best_entry_key = best_entry_key.clone();
295+
let best_entry_key = module_group_map
296+
.iter()
297+
.min_by(|a, b| {
298+
if compare_entries(a.1, b.1) < 0f64 {
299+
Ordering::Greater
300+
} else {
301+
Ordering::Less
302+
}
303+
})
304+
.map(|(key, _)| key.clone())
305+
.expect("at least have one item");
306+
306307
let best_module_group = module_group_map
307308
.remove(&best_entry_key)
308309
.expect("This should never happen, please file an issue");
@@ -480,8 +481,7 @@ impl SplitChunksPlugin {
480481
) {
481482
// remove all modules from other entries and update size
482483
let keys_of_invalid_group = module_group_map
483-
.iter_mut()
484-
.par_bridge()
484+
.par_iter_mut()
485485
.filter_map(|(key, other_module_group)| {
486486
other_module_group
487487
.chunks

0 commit comments

Comments
 (0)