-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: mem cache for chunk render source (#8528)
- Loading branch information
Showing
19 changed files
with
386 additions
and
377 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use futures::Future; | ||
use rspack_collections::Identifier; | ||
use rspack_error::{Diagnostic, Result}; | ||
use rspack_sources::BoxSource; | ||
|
||
use crate::{old_cache::storage, Chunk, Compilation, SourceType}; | ||
|
||
type Storage = dyn storage::Storage<(BoxSource, Vec<Diagnostic>)>; | ||
|
||
#[derive(Debug)] | ||
pub struct ChunkRenderOccasion { | ||
storage: Option<Box<Storage>>, | ||
} | ||
|
||
impl ChunkRenderOccasion { | ||
pub fn new(storage: Option<Box<Storage>>) -> Self { | ||
Self { storage } | ||
} | ||
|
||
pub async fn use_cache<G, F>( | ||
&self, | ||
compilation: &Compilation, | ||
chunk: &Chunk, | ||
source_type: &SourceType, | ||
generator: G, | ||
) -> Result<(BoxSource, Vec<Diagnostic>)> | ||
where | ||
G: FnOnce() -> F, | ||
F: Future<Output = Result<(BoxSource, Vec<Diagnostic>)>>, | ||
{ | ||
let storage = match &self.storage { | ||
Some(s) => s, | ||
// no cache return directly | ||
None => return generator().await, | ||
}; | ||
|
||
let Some(content_hash) = | ||
chunk.content_hash_by_source_type(&compilation.chunk_hashes_results, source_type) | ||
else { | ||
return generator().await; | ||
}; | ||
let cache_key = Identifier::from(content_hash.encoded()); | ||
if let Some(value) = storage.get(&cache_key) { | ||
Ok(value) | ||
} else { | ||
let res = generator().await?; | ||
storage.set(cache_key, res.clone()); | ||
Ok(res) | ||
} | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
crates/rspack_core/src/old_cache/occasion/create_chunk_assets.rs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
2edb6b4
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
2edb6b4
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.
📝 Benchmark detail: Open
Threshold exceeded: ["10000_big_production-mode_disable-minimize + exec","threejs_development-mode_10x_hmr + rss memory"]