Skip to content

Commit

Permalink
perf: put visited_chunk_group_keys out of the loop and use FxHashMap (#…
Browse files Browse the repository at this point in the history
…6769)

perf: put visited_chunk_group_keys out of the loop and use FxHashMap and FxHashSet
  • Loading branch information
SyMind authored Jun 11, 2024
1 parent 4fcc42c commit db6c8be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rspack_plugin_ensure_chunk_conditions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ version = "0.1.0"
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_hook = { path = "../rspack_hook" }
rustc-hash = { workspace = true }
13 changes: 6 additions & 7 deletions crates/rspack_plugin_ensure_chunk_conditions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::collections::{HashMap, HashSet};

use rspack_core::{
get_chunk_from_ukey, get_chunk_group_from_ukey, Compilation, CompilationOptimizeChunks, Logger,
Plugin, PluginContext,
};
use rspack_error::Result;
use rspack_hook::{plugin, plugin_hook};
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

#[plugin]
#[derive(Debug, Default)]
Expand All @@ -16,7 +15,7 @@ fn optimize_chunks(&self, compilation: &mut Compilation) -> Result<Option<bool>>
let logger = compilation.get_logger(self.name());
let start = logger.time("ensure chunk conditions");

let mut source_module_chunks = HashMap::new();
let mut source_module_chunks = HashMap::default();
compilation
.get_module_graph()
.modules()
Expand All @@ -38,14 +37,14 @@ fn optimize_chunks(&self, compilation: &mut Compilation) -> Result<Option<bool>>
}
});

let mut target_module_chunks = HashMap::new();

let mut target_module_chunks = HashMap::default();
let mut visited_chunk_group_keys = HashSet::default();
for (module_id, chunk_keys) in &source_module_chunks {
let mut target_chunks = HashSet::new();
let mut target_chunks = HashSet::default();
for chunk_key in chunk_keys {
if let Some(chunk) = get_chunk_from_ukey(chunk_key, &compilation.chunk_by_ukey) {
let mut chunk_group_keys = chunk.groups.iter().collect::<Vec<_>>();
let mut visited_chunk_group_keys = HashSet::new();
visited_chunk_group_keys.clear();
'out: while let Some(chunk_group_key) = chunk_group_keys.pop() {
if visited_chunk_group_keys.contains(chunk_group_key) {
continue;
Expand Down

2 comments on commit db6c8be

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-06-11 34bb9ea) Current Change
10000_development-mode + exec 2.24 s ± 26 ms 2.23 s ± 14 ms -0.15 %
10000_development-mode_hmr + exec 737 ms ± 14 ms 733 ms ± 13 ms -0.44 %
10000_production-mode + exec 2.58 s ± 21 ms 2.58 s ± 21 ms -0.19 %
arco-pro_development-mode + exec 1.92 s ± 78 ms 1.93 s ± 78 ms +0.61 %
arco-pro_development-mode_hmr + exec 441 ms ± 1.3 ms 442 ms ± 1.4 ms +0.12 %
arco-pro_production-mode + exec 3.51 s ± 71 ms 3.54 s ± 138 ms +0.94 %
threejs_development-mode_10x + exec 1.41 s ± 15 ms 1.41 s ± 15 ms +0.27 %
threejs_development-mode_10x_hmr + exec 802 ms ± 6.9 ms 806 ms ± 6.9 ms +0.48 %
threejs_production-mode_10x + exec 4.71 s ± 20 ms 4.71 s ± 30 ms -0.01 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ✅ success
rspress ❌ failure
rsbuild ❌ failure
compat ✅ success
examples ✅ success

Please sign in to comment.