Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: put visited_chunk_group_keys out of the loop and use FxHashMap #6769

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading