Skip to content

Commit 4e3a5e8

Browse files
authored
feat: persistent cache save ModuleProfiler (#11715)
1 parent 902ceff commit 4e3a5e8

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

crates/rspack_core/src/module_graph/module.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub struct ModuleGraphModule {
2222
pub(crate) pre_order_index: Option<u32>,
2323
pub post_order_index: Option<u32>,
2424
pub exports: ExportsInfo,
25-
#[cacheable(with=Skip)]
2625
pub profile: Option<ModuleProfile>,
2726
pub depth: Option<usize>,
2827
pub optimization_bailout: Vec<String>,

crates/rspack_core/src/module_profile.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
use std::time::Instant;
22

3+
use rspack_cacheable::{
4+
cacheable,
5+
with::{Custom, CustomConverter},
6+
};
7+
8+
#[cacheable(with=Custom)]
39
#[derive(Debug, Default, Clone)]
410
enum ProfileState {
511
#[default]
@@ -9,6 +15,26 @@ enum ProfileState {
915
Finish(u64),
1016
}
1117

18+
impl CustomConverter for ProfileState {
19+
type Target = Option<u64>;
20+
fn serialize(
21+
&self,
22+
_ctx: &dyn std::any::Any,
23+
) -> Result<Self::Target, rspack_cacheable::SerializeError> {
24+
Ok(self.duration())
25+
}
26+
fn deserialize(
27+
data: Self::Target,
28+
_ctx: &dyn std::any::Any,
29+
) -> Result<Self, rspack_cacheable::DeserializeError> {
30+
if let Some(time) = data {
31+
Ok(ProfileState::Finish(time))
32+
} else {
33+
Ok(ProfileState::default())
34+
}
35+
}
36+
}
37+
1238
impl ProfileState {
1339
fn start(&mut self) {
1440
*self = Self::Started(Instant::now())
@@ -35,6 +61,7 @@ impl ProfileState {
3561
// https://github.com/webpack/webpack/blob/4809421990a20dfefa06e6445191e65001e75f88/lib/ModuleProfile.js
3662
// NOTE: Rspack has different cache design, remove cache related profiles
3763

64+
#[cacheable]
3865
#[derive(Debug, Default, Clone)]
3966
pub struct ModuleProfile {
4067
factory: ProfileState,

crates/rspack_plugin_wasm/src/parser_and_generator.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::{
55
};
66

77
use indexmap::IndexMap;
8-
use rspack_cacheable::{cacheable, cacheable_dyn, with::Unsupported};
8+
use rspack_cacheable::{
9+
cacheable, cacheable_dyn,
10+
with::{AsInner, AsMap},
11+
};
912
use rspack_collections::Identifier;
1013
use rspack_core::{
1114
AssetInfo, BoxDependency, BuildMetaExportsType, ChunkGraph, Compilation,
@@ -26,7 +29,7 @@ use crate::{ModuleIdToFileName, dependency::WasmImportDependency};
2629
#[cacheable]
2730
#[derive(Debug)]
2831
pub struct AsyncWasmParserAndGenerator {
29-
#[cacheable(with=Unsupported)]
32+
#[cacheable(with=AsInner<AsMap>)]
3033
pub(crate) module_id_to_filename: ModuleIdToFileName,
3134
}
3235

0 commit comments

Comments
 (0)