-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cache for process runtime requirements (#7601)
- Loading branch information
Showing
13 changed files
with
219 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::*; |
52 changes: 52 additions & 0 deletions
52
crates/rspack_core/src/old_cache/occasion/process_runtime_requirements.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RuntimeGlobals>; | ||
|
||
#[derive(Debug)] | ||
pub struct ProcessRuntimeRequirementsOccasion { | ||
storage: Option<Box<Storage>>, | ||
} | ||
|
||
impl ProcessRuntimeRequirementsOccasion { | ||
pub fn new(storage: Option<Box<Storage>>) -> 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<RuntimeGlobals>, | ||
) -> Result<RuntimeGlobals> { | ||
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.
0148015
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Ran ecosystem CI: Open