From c2dfd630a80a4db05c9bfa85bb24895ee9195479 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Fri, 16 Aug 2024 20:33:49 +0800 Subject: [PATCH] feat: cache process runtime requirements --- .../src/codegen_result.rs | 3 +- .../src/build_chunk_graph/code_splitter.rs | 4 +- crates/rspack_core/src/chunk.rs | 4 +- .../src/chunk_graph/chunk_graph_module.rs | 2 +- .../rspack_core/src/compiler/compilation.rs | 136 ++++++++---------- crates/rspack_core/src/compiler/hmr.rs | 16 +-- .../src/compiler/module_executor/execute.rs | 19 +-- crates/rspack_core/src/old_cache/mod.rs | 8 +- .../src/old_cache/occasion/code_generate.rs | 1 + .../rspack_core/src/old_cache/occasion/mod.rs | 2 + .../occasion/process_runtime_requirements.rs | 52 +++++++ crates/rspack_core/src/runtime.rs | 124 ++++++++++------ .../src/runtime_plugin.rs | 2 +- 13 files changed, 219 insertions(+), 154 deletions(-) create mode 100644 crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs diff --git a/crates/rspack_binding_values/src/codegen_result.rs b/crates/rspack_binding_values/src/codegen_result.rs index b5618c69828..4d258228b87 100644 --- a/crates/rspack_binding_values/src/codegen_result.rs +++ b/crates/rspack_binding_values/src/codegen_result.rs @@ -41,7 +41,8 @@ impl From for JsCodegenerationResults { rspack_core::RuntimeMode::Empty => {} rspack_core::RuntimeMode::SingleEntry => { runtime_map.insert( - get_runtime_key(runtime_result_map.single_runtime.expect("exist")), + get_runtime_key(runtime_result_map.single_runtime.as_ref().expect("exist")) + .to_string(), id_result_map .get(&runtime_result_map.single_value.expect("TODO")) .expect("TODO") diff --git a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs index 84014cf44ae..05375b3656f 100644 --- a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs @@ -15,7 +15,7 @@ use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet, FxHasher}; use crate::dependencies_block::AsyncDependenciesToInitialChunkError; use crate::{ - add_connection_states, assign_depth, assign_depths, get_entry_runtime, + add_connection_states, assign_depth, assign_depths, get_entry_runtime, merge_runtime, AsyncDependenciesBlockIdentifier, ChunkGroup, ChunkGroupKind, ChunkGroupOptions, ChunkGroupUkey, ChunkLoading, ChunkUkey, Compilation, ConnectionId, ConnectionState, DependenciesBlock, EntryDependency, EntryRuntime, GroupOptions, Logger, ModuleDependency, ModuleGraph, @@ -791,7 +791,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on .chunk_by_ukey .entry(*chunk_ukey) .and_modify(|chunk| { - chunk.runtime.extend(cgi.runtime.clone()); + chunk.runtime = merge_runtime(&chunk.runtime, &cgi.runtime); }); } } diff --git a/crates/rspack_core/src/chunk.rs b/crates/rspack_core/src/chunk.rs index 87e911b45a5..3b117fd07a5 100644 --- a/crates/rspack_core/src/chunk.rs +++ b/crates/rspack_core/src/chunk.rs @@ -9,7 +9,7 @@ use rspack_hash::{RspackHash, RspackHashDigest}; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet, FxHasher}; use crate::{ - compare_chunk_group, get_chunk_group_from_ukey, sort_group_by_index, ChunkGraph, + compare_chunk_group, get_chunk_group_from_ukey, merge_runtime, sort_group_by_index, ChunkGraph, ChunkGroupOrderKey, }; use crate::{ChunkGroupByUkey, ChunkGroupUkey, ChunkUkey, SourceType}; @@ -117,7 +117,7 @@ impl Chunk { new_chunk.add_group(group.ukey); }); new_chunk.id_name_hints.extend(self.id_name_hints.clone()); - new_chunk.runtime.extend(self.runtime.clone()); + new_chunk.runtime = merge_runtime(&new_chunk.runtime, &self.runtime); } pub fn can_be_initial(&self, chunk_group_by_ukey: &ChunkGroupByUkey) -> bool { diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs index 9ae1410ef8e..4dde1f9418a 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_module.rs @@ -189,7 +189,7 @@ impl ChunkGraph { cgm.hashes = Some(hashes); } - #[instrument(name = "chunk_graph:get_module_graph_hash", skip_all)] + #[instrument(name = "chunk_graph:get_module_graph_hash", skip_all, fields(module = ?module.identifier()))] pub fn get_module_graph_hash( &self, module: &dyn Module, diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index edc862a2dda..a2bce543933 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -61,7 +61,7 @@ define_hook!(CompilationOptimizeChunkModules: AsyncSeriesBail(compilation: &mut define_hook!(CompilationModuleIds: SyncSeries(compilation: &mut Compilation)); define_hook!(CompilationChunkIds: SyncSeries(compilation: &mut Compilation)); define_hook!(CompilationRuntimeModule: AsyncSeries(compilation: &mut Compilation, module: &ModuleIdentifier, chunk: &ChunkUkey)); -define_hook!(CompilationRuntimeRequirementInModule: SyncSeriesBail(compilation: &mut Compilation, module_identifier: &ModuleIdentifier, runtime_requirements: &RuntimeGlobals, runtime_requirements_mut: &mut RuntimeGlobals)); +define_hook!(CompilationRuntimeRequirementInModule: SyncSeriesBail(compilation: &Compilation, module_identifier: &ModuleIdentifier, runtime_requirements: &RuntimeGlobals, runtime_requirements_mut: &mut RuntimeGlobals)); define_hook!(CompilationAdditionalChunkRuntimeRequirements: SyncSeries(compilation: &mut Compilation, chunk_ukey: &ChunkUkey, runtime_requirements: &mut RuntimeGlobals)); define_hook!(CompilationAdditionalTreeRuntimeRequirements: AsyncSeries(compilation: &mut Compilation, chunk_ukey: &ChunkUkey, runtime_requirements: &mut RuntimeGlobals)); define_hook!(CompilationRuntimeRequirementInTree: SyncSeriesBail(compilation: &mut Compilation, chunk_ukey: &ChunkUkey, runtime_requirements: &RuntimeGlobals, runtime_requirements_mut: &mut RuntimeGlobals)); @@ -757,7 +757,7 @@ impl Compilation { cache_counter: &mut Option, filter_op: impl Fn(&(ModuleIdentifier, &Box)) -> bool + Sync + Send, ) -> Result<()> { - let results = compilation.code_generation_modules( + compilation.code_generation_modules( cache_counter, compilation .get_module_graph() @@ -766,15 +766,7 @@ impl Compilation { .filter(filter_op) .map(|(id, _)| id) .collect(), - )?; - - results.iter().for_each(|module_identifier| { - compilation - .code_generated_modules - .insert(*module_identifier); - }); - - Ok(()) + ) } run_iteration(self, &mut codegen_cache_counter, |(_, module)| { @@ -796,7 +788,7 @@ impl Compilation { &mut self, cache_counter: &mut Option, modules: IdentifierSet, - ) -> Result> { + ) -> Result<()> { let chunk_graph = &self.chunk_graph; let module_graph = self.get_module_graph(); let mut jobs = Vec::new(); @@ -860,31 +852,28 @@ impl Compilation { .map(|(res, runtimes, from_cache)| (module, res, runtimes, from_cache)) }) .collect::>>()?; - let results = results - .into_iter() - .map(|(module, codegen_res, runtimes, from_cache)| { - if let Some(counter) = cache_counter { - if from_cache { - counter.hit(); - } else { - counter.miss(); - } + for (module, codegen_res, runtimes, from_cache) in results { + if let Some(counter) = cache_counter { + if from_cache { + counter.hit(); + } else { + counter.miss(); } + } - let codegen_res_id = codegen_res.id; + let codegen_res_id = codegen_res.id; + self + .code_generation_results + .module_generation_result_map + .insert(codegen_res_id, codegen_res); + for runtime in runtimes { self .code_generation_results - .module_generation_result_map - .insert(codegen_res_id, codegen_res); - for runtime in runtimes { - self - .code_generation_results - .add(module, runtime, codegen_res_id); - } - module - }); - - Ok(results.collect()) + .add(module, runtime, codegen_res_id); + } + self.code_generated_modules.insert(module); + } + Ok(()) } #[instrument(name = "compilation::create_module_assets", skip_all)] @@ -1324,52 +1313,49 @@ impl Compilation { let logger = self.get_logger("rspack.Compilation"); let start = logger.time("runtime requirements.modules"); - let mut module_runtime_requirements = modules + let results: Vec<(ModuleIdentifier, RuntimeSpec, RuntimeGlobals)> = modules .into_par_iter() - .filter_map(|module_identifier| { - if self + .filter(|module| self.chunk_graph.get_number_of_module_chunks(*module) > 0) + .flat_map(|module| { + self .chunk_graph - .get_number_of_module_chunks(module_identifier) - > 0 - { - let mut module_runtime_requirements: Vec<(RuntimeSpec, RuntimeGlobals)> = vec![]; - for runtime in self - .chunk_graph - .get_module_runtimes(module_identifier, &self.chunk_by_ukey) - .values() - { - let runtime_requirements = self + .get_module_runtimes(module, &self.chunk_by_ukey) + .into_values() + .map(|runtime| (module, runtime)) + .collect::>() + }) + .map(|(module, runtime)| { + let runtime_requirements = self + .old_cache + .process_runtime_requirements_occasion + .use_cache(module, &runtime, self, |module, runtime| { + let mut runtime_requirements = self .code_generation_results - .get_runtime_requirements(&module_identifier, Some(runtime)); - module_runtime_requirements.push((runtime.clone(), runtime_requirements)); - } - return Some((module_identifier, module_runtime_requirements)); - } - None + .get_runtime_requirements(&module, Some(runtime)); + process_runtime_requirement_hook( + &mut runtime_requirements, + |runtime_requirements, runtime_requirements_mut| { + plugin_driver + .compilation_hooks + .runtime_requirement_in_module + .call( + self, + &module, + runtime_requirements, + runtime_requirements_mut, + )?; + Ok(()) + }, + )?; + Ok(runtime_requirements) + })?; + Ok((module, runtime, runtime_requirements)) }) - .collect::>(); - - for (module_identifier, runtime_requirements) in module_runtime_requirements.iter_mut() { - for (runtime, requirements) in runtime_requirements.iter_mut() { - process_runtime_requirement_hook( - requirements, - |runtime_requirements, runtime_requirements_mut| { - plugin_driver - .compilation_hooks - .runtime_requirement_in_module - .call( - self, - module_identifier, - runtime_requirements, - runtime_requirements_mut, - )?; - Ok(()) - }, - )?; - self - .chunk_graph - .add_module_runtime_requirements(*module_identifier, runtime, *requirements) - } + .collect::>()?; + for (module, runtime, runtime_requirements) in results { + self + .chunk_graph + .add_module_runtime_requirements(module, &runtime, runtime_requirements); } logger.time_end(start); diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index 410a6ef358b..8072f709c36 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -27,14 +27,14 @@ where let (old_all_modules, old_runtime_modules) = collect_changed_modules(old.compilation)?; // TODO: should use `records` - let mut all_old_runtime: RuntimeSpec = Default::default(); - for entry_ukey in old.compilation.get_chunk_graph_entries() { - if let Some(runtime) = get_chunk_from_ukey(&entry_ukey, &old.compilation.chunk_by_ukey) - .map(|entry_chunk| entry_chunk.runtime.clone()) - { - all_old_runtime.extend(runtime); - } - } + let all_old_runtime = RuntimeSpec::from_iter( + old + .compilation + .get_chunk_graph_entries() + .into_iter() + .filter_map(|entry_ukey| get_chunk_from_ukey(&entry_ukey, &old.compilation.chunk_by_ukey)) + .flat_map(|entry_chunk| entry_chunk.runtime.clone()), + ); let mut old_chunks: Vec<(String, RuntimeSpec)> = vec![]; for (_, chunk) in old.compilation.chunk_by_ukey.iter() { diff --git a/crates/rspack_core/src/compiler/module_executor/execute.rs b/crates/rspack_core/src/compiler/module_executor/execute.rs index db14705659f..425189f0bdc 100644 --- a/crates/rspack_core/src/compiler/module_executor/execute.rs +++ b/crates/rspack_core/src/compiler/module_executor/execute.rs @@ -100,11 +100,7 @@ impl Task for ExecuteTask { chunk.id = chunk.name.clone(); chunk.ids = vec![chunk.id.clone().expect("id is set")]; - let runtime = { - let mut runtime = RuntimeSpec::default(); - runtime.insert("build time".into()); - runtime - }; + let runtime = RuntimeSpec::from_iter(once("build time".into())); chunk.runtime = runtime.clone(); @@ -163,21 +159,12 @@ impl Task for ExecuteTask { compilation.create_module_hashes(modules.par_iter().copied())?; - let code_generation_results = - compilation.code_generation_modules(&mut None, modules.clone())?; - - code_generation_results - .iter() - .for_each(|module_identifier| { - compilation - .code_generated_modules - .insert(*module_identifier); - }); + compilation.code_generation_modules(&mut None, modules.clone())?; Handle::current().block_on(async { compilation .process_runtime_requirements( - modules.clone(), + Vec::from_iter(modules.iter().copied()), once(chunk_ukey), once(chunk_ukey), compilation.plugin_driver.clone(), diff --git a/crates/rspack_core/src/old_cache/mod.rs b/crates/rspack_core/src/old_cache/mod.rs index d274f1e6331..a9876f1be26 100644 --- a/crates/rspack_core/src/old_cache/mod.rs +++ b/crates/rspack_core/src/old_cache/mod.rs @@ -12,13 +12,16 @@ mod local; mod occasion; mod storage; pub use local::*; -use occasion::{CodeGenerateOccasion, CreateChunkAssetsOccasion}; +use occasion::{ + CodeGenerateOccasion, CreateChunkAssetsOccasion, ProcessRuntimeRequirementsOccasion, +}; use storage::new_storage; #[derive(Debug)] pub struct Cache { is_idle: AtomicBool, pub code_generate_occasion: CodeGenerateOccasion, + pub process_runtime_requirements_occasion: ProcessRuntimeRequirementsOccasion, pub create_chunk_assets_occasion: CreateChunkAssetsOccasion, } @@ -27,6 +30,9 @@ impl Cache { Self { is_idle: true.into(), code_generate_occasion: CodeGenerateOccasion::new(new_storage(&options.cache)), + process_runtime_requirements_occasion: ProcessRuntimeRequirementsOccasion::new(new_storage( + &options.cache, + )), create_chunk_assets_occasion: CreateChunkAssetsOccasion::new(new_storage(&options.cache)), } } diff --git a/crates/rspack_core/src/old_cache/occasion/code_generate.rs b/crates/rspack_core/src/old_cache/occasion/code_generate.rs index e824c2d4f73..9fdef9fe274 100644 --- a/crates/rspack_core/src/old_cache/occasion/code_generate.rs +++ b/crates/rspack_core/src/old_cache/occasion/code_generate.rs @@ -16,6 +16,7 @@ impl CodeGenerateOccasion { Self { storage } } + #[tracing::instrument(skip_all, fields(module = ?job.module))] pub fn use_cache( &self, job: CodeGenerationJob, diff --git a/crates/rspack_core/src/old_cache/occasion/mod.rs b/crates/rspack_core/src/old_cache/occasion/mod.rs index 5d9bb2adf8d..fa093479f95 100644 --- a/crates/rspack_core/src/old_cache/occasion/mod.rs +++ b/crates/rspack_core/src/old_cache/occasion/mod.rs @@ -1,4 +1,6 @@ mod code_generate; pub use code_generate::*; +mod process_runtime_requirements; +pub use process_runtime_requirements::*; mod create_chunk_assets; pub use create_chunk_assets::*; diff --git a/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs b/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs new file mode 100644 index 00000000000..84ce6182a37 --- /dev/null +++ b/crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs @@ -0,0 +1,52 @@ +use rspack_collections::Identifier; +use rspack_error::Result; + +use crate::old_cache::storage; +use crate::{get_runtime_key, Compilation, ModuleIdentifier, RuntimeGlobals, RuntimeSpec}; + +type Storage = dyn storage::Storage; + +#[derive(Debug)] +pub struct ProcessRuntimeRequirementsOccasion { + storage: Option>, +} + +impl ProcessRuntimeRequirementsOccasion { + pub fn new(storage: Option>) -> Self { + Self { storage } + } + + #[tracing::instrument(skip_all, fields(module = ?module))] + pub fn use_cache( + &self, + module: ModuleIdentifier, + runtime: &RuntimeSpec, + compilation: &Compilation, + provide: impl Fn(ModuleIdentifier, &RuntimeSpec) -> Result, + ) -> Result { + let storage = match &self.storage { + Some(s) => s, + None => { + let res = provide(module, runtime)?; + return Ok(res); + } + }; + let hash = compilation + .chunk_graph + .get_module_hash(module, runtime) + .expect("should have cgm hash in process_runtime_requirements"); + let cache_key = Identifier::from(format!( + "{}|{}|{}", + module, + hash.encoded(), + get_runtime_key(runtime) + )); + if let Some(value) = storage.get(&cache_key) { + Ok(value) + } else { + let res = provide(module, runtime)?; + storage.set(cache_key, res); + Ok(res) + } + } +} diff --git a/crates/rspack_core/src/runtime.rs b/crates/rspack_core/src/runtime.rs index bf3e8f31e5a..c8c72a3faaf 100644 --- a/crates/rspack_core/src/runtime.rs +++ b/crates/rspack_core/src/runtime.rs @@ -1,59 +1,61 @@ use std::collections::hash_map::IntoValues; -use std::ops::{Deref, DerefMut}; +use std::collections::hash_set; +use std::ops::Deref; use std::{cmp::Ordering, fmt::Debug, sync::Arc}; -use rspack_util::fx_hash::FxIndexSet; -use rustc_hash::FxHashMap as HashMap; +use rustc_hash::{FxHashMap as HashMap, FxHashSet}; use crate::{EntryOptions, EntryRuntime}; #[derive(Debug, Default, Clone, PartialEq, Eq)] -pub struct RuntimeSpec(FxIndexSet>); +pub struct RuntimeSpec { + inner: FxHashSet>, + key: String, +} impl std::hash::Hash for RuntimeSpec { fn hash(&self, state: &mut H) { - self.0.iter().for_each(|item| item.hash(state)); + self.key.hash(state); } } impl Deref for RuntimeSpec { - type Target = FxIndexSet>; + type Target = FxHashSet>; fn deref(&self) -> &Self::Target { - &self.0 + &self.inner } } -impl DerefMut for RuntimeSpec { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl From>> for RuntimeSpec { - fn from(value: FxIndexSet>) -> Self { +impl From>> for RuntimeSpec { + fn from(value: FxHashSet>) -> Self { Self::new(value) } } impl FromIterator> for RuntimeSpec { fn from_iter>>(iter: T) -> Self { - Self(FxIndexSet::from_iter(iter)) + Self::new(FxHashSet::from_iter(iter)) } } impl IntoIterator for RuntimeSpec { type Item = Arc; - type IntoIter = indexmap::set::IntoIter; + type IntoIter = hash_set::IntoIter; fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() + self.inner.into_iter() } } impl RuntimeSpec { - pub fn new(inner: FxIndexSet>) -> Self { - Self(inner) + pub fn new(inner: FxHashSet>) -> Self { + let mut this = Self { + inner, + key: String::new(), + }; + this.update_key(); + this } pub fn from_entry(entry: &str, runtime: Option<&EntryRuntime>) -> Self { @@ -74,8 +76,29 @@ impl RuntimeSpec { } pub fn subtract(&self, b: &RuntimeSpec) -> Self { - let res = &self.0 - &b.0; - Self(res) + let res = &self.inner - &b.inner; + Self::new(res) + } + + pub fn insert(&mut self, r: Arc) -> bool { + let update = self.inner.insert(r); + if update { + self.update_key(); + } + update + } + + fn update_key(&mut self) { + if self.inner.is_empty() { + if self.key.is_empty() { + return; + } + self.key = String::new(); + return; + } + let mut ordered = Vec::from_iter(self.inner.iter().cloned()); + ordered.sort_unstable(); + self.key = ordered.join("\n") } } @@ -133,14 +156,14 @@ impl RuntimeCondition { } pub fn merge_runtime(a: &RuntimeSpec, b: &RuntimeSpec) -> RuntimeSpec { - let mut set: RuntimeSpec = Default::default(); + let mut set = FxHashSet::default(); for r in a.iter() { set.insert(r.clone()); } for r in b.iter() { set.insert(r.clone()); } - set + RuntimeSpec::new(set) } pub fn runtime_to_string(runtime: &RuntimeSpec) -> String { @@ -157,14 +180,14 @@ pub fn filter_runtime( Some(runtime) => { let mut some = false; let mut every = true; - let mut result = RuntimeSpec::default(); + let mut result = FxHashSet::default(); for r in runtime.iter() { let cur = RuntimeSpec::from_iter([r.clone()]); let v = filter(Some(&cur)); if v { some = true; - result = merge_runtime(&result, &cur); + result.insert(r.clone()); } else { every = false; } @@ -175,7 +198,7 @@ pub fn filter_runtime( } else if every { RuntimeCondition::Boolean(true) } else { - RuntimeCondition::Spec(result) + RuntimeCondition::Spec(RuntimeSpec::new(result)) } } } @@ -231,7 +254,7 @@ pub fn subtract_runtime_condition( (_, RuntimeCondition::Boolean(false)) => return a.clone(), (RuntimeCondition::Boolean(false), _) => return RuntimeCondition::Boolean(false), (RuntimeCondition::Spec(a), RuntimeCondition::Spec(b)) => { - let mut set = FxIndexSet::default(); + let mut set = FxHashSet::default(); for item in a.iter() { if !b.contains(item) { set.insert(item.clone()); @@ -240,14 +263,17 @@ pub fn subtract_runtime_condition( set } (RuntimeCondition::Boolean(true), RuntimeCondition::Spec(b)) => { - let a = runtime.cloned().unwrap_or_default(); - let mut set = FxIndexSet::default(); - for item in a.iter() { - if !b.contains(item) { - set.insert(item.clone()); + if let Some(a) = runtime { + let mut set = FxHashSet::default(); + for item in a.iter() { + if !b.contains(item) { + set.insert(item.clone()); + } } + set + } else { + FxHashSet::default() } - set } }; if merged.is_empty() { @@ -256,18 +282,16 @@ pub fn subtract_runtime_condition( RuntimeCondition::Spec(merged.into()) } -pub fn get_runtime_key(runtime: RuntimeSpec) -> String { - let mut runtime: Vec> = Vec::from_iter(runtime); - runtime.sort_unstable(); - runtime.join("\n") +pub fn get_runtime_key(runtime: &RuntimeSpec) -> &str { + &runtime.key } pub fn compare_runtime(a: &RuntimeSpec, b: &RuntimeSpec) -> Ordering { if a == b { return Ordering::Equal; } - let a_key = get_runtime_key(a.clone()); - let b_key = get_runtime_key(b.clone()); + let a_key = get_runtime_key(a); + let b_key = get_runtime_key(b); if a_key < b_key { return Ordering::Less; } @@ -318,7 +342,7 @@ impl RuntimeSpecMap { None } } - RuntimeMode::Map => self.map.get(&get_runtime_key(runtime.clone())), + RuntimeMode::Map => self.map.get(get_runtime_key(runtime)), } } @@ -334,7 +358,7 @@ impl RuntimeSpecMap { None } } - RuntimeMode::Map => self.map.get_mut(&get_runtime_key(runtime.clone())), + RuntimeMode::Map => self.map.get_mut(get_runtime_key(runtime)), } } @@ -364,12 +388,16 @@ impl RuntimeSpecMap { self .map - .insert(get_runtime_key(single_runtime), single_value); - self.map.insert(get_runtime_key(runtime), value); + .insert(get_runtime_key(&single_runtime).to_string(), single_value); + self + .map + .insert(get_runtime_key(&runtime).to_string(), value); } } RuntimeMode::Map => { - self.map.insert(get_runtime_key(runtime), value); + self + .map + .insert(get_runtime_key(&runtime).to_string(), value); } } } @@ -393,11 +421,13 @@ pub struct RuntimeSpecSet { impl RuntimeSpecSet { pub fn get(&self, runtime: &RuntimeSpec) -> Option<&RuntimeSpec> { - self.map.get(&get_runtime_key(runtime.clone())) + self.map.get(get_runtime_key(runtime)) } pub fn set(&mut self, runtime: RuntimeSpec) { - self.map.insert(get_runtime_key(runtime.clone()), runtime); + self + .map + .insert(get_runtime_key(&runtime).to_string(), runtime); } pub fn values(&self) -> Vec<&RuntimeSpec> { diff --git a/crates/rspack_plugin_runtime/src/runtime_plugin.rs b/crates/rspack_plugin_runtime/src/runtime_plugin.rs index a3808b1411d..3a4bce9dead 100644 --- a/crates/rspack_plugin_runtime/src/runtime_plugin.rs +++ b/crates/rspack_plugin_runtime/src/runtime_plugin.rs @@ -179,7 +179,7 @@ async fn js_chunk_hash( #[plugin_hook(CompilationRuntimeRequirementInModule for RuntimePlugin)] fn runtime_requirements_in_module( &self, - _compilation: &mut Compilation, + _compilation: &Compilation, _module: &ModuleIdentifier, runtime_requirements: &RuntimeGlobals, runtime_requirements_mut: &mut RuntimeGlobals,