Skip to content

Commit

Permalink
fix: persistent cache save ModuleArgumentDependency.id (#8870)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz authored Dec 27, 2024
1 parent 99d30df commit d0393f1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ use rspack_util::ext::DynHash;
#[cacheable]
#[derive(Debug, Clone)]
pub struct ModuleArgumentDependency {
#[cacheable(with=Skip)]
id: Option<&'static str>,
id: Option<String>,
range: DependencyRange,
#[cacheable(with=Skip)]
source_map: Option<SharedSourceMap>,
}

impl ModuleArgumentDependency {
pub fn new(
id: Option<&'static str>,
id: Option<String>,
range: DependencyRange,
source_map: Option<SharedSourceMap>,
) -> Self {
Expand Down Expand Up @@ -55,7 +54,7 @@ impl DependencyTemplate for ModuleArgumentDependency {
.expect("should have mgm")
.get_module_argument();

let content = if let Some(id) = self.id {
let content = if let Some(id) = &self.id {
format!("{module_argument}.{id}")
} else {
format!("{module_argument}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl JavascriptParserPlugin for APIPlugin {
parser
.presentational_dependencies
.push(Box::new(ModuleArgumentDependency::new(
Some("id"),
Some("id".into()),
expr.span().into(),
Some(parser.source_map.clone()),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl JavascriptParser<'_> {
self
.presentational_dependencies
.push(Box::new(ModuleArgumentDependency::new(
Some("hot"),
Some("hot".into()),
span.into(),
Some(self.source_map.clone()),
)));
Expand All @@ -59,7 +59,7 @@ impl JavascriptParser<'_> {
self
.presentational_dependencies
.push(Box::new(ModuleArgumentDependency::new(
Some("hot.accept"),
Some("hot.accept".into()),
call_expr.callee.span().into(),
Some(self.source_map.clone()),
)));
Expand Down Expand Up @@ -95,7 +95,7 @@ impl JavascriptParser<'_> {
self
.presentational_dependencies
.push(Box::new(ModuleArgumentDependency::new(
Some("hot.decline"),
Some("hot.decline".into()),
call_expr.callee.span().into(),
Some(self.source_map.clone()),
)));
Expand Down
2 changes: 2 additions & 0 deletions packages/rspack-test-tools/etc/test-tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
// (undocumented)
afterAll(context: ITestContext): Promise<void>;
// (undocumented)
build(context: ITestContext): Promise<void>;
// (undocumented)
protected _cacheOptions: ICacheProcessorOptions<T>;
// (undocumented)
static defaultOptions<T extends ECompilerType>(this: CacheProcessor<T>, context: ITestContext): TCompilerOptions<T>;
Expand Down
20 changes: 20 additions & 0 deletions packages/rspack-test-tools/src/processor/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "node:path";
import { rspack } from "@rspack/core";
import { removeSync } from "fs-extra";

import { TestHotUpdatePlugin } from "../helper/plugins";
import {
Expand Down Expand Up @@ -37,6 +38,25 @@ export class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
this.updateOptions = fakeUpdateLoaderOptions;
}

async build(context: ITestContext): Promise<void> {
// clear cache directory first time.
const experiments =
this.getCompiler(context).getOptions().experiments || {};
let directory = "";
if (
"cache" in experiments &&
typeof experiments.cache === "object" &&
experiments.cache.type === "persistent"
) {
directory = experiments.cache.storage?.directory || directory;
}
removeSync(
path.join(context.getSource(), directory || "node_modules/.cache")
);

await super.build(context);
}

async run(env: ITestEnv, context: ITestContext) {
context.setValue(
this._options.name,
Expand Down
6 changes: 1 addition & 5 deletions packages/rspack-test-tools/tests/Cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
const path = require("path");
const { describeByWalk, createCacheCase } = require("../dist");

function v(name) {
return path.join(__dirname, `cache ${name}`);
}

// Run tests rspack-test-tools/tests/cacheCases in target async-node
describeByWalk(
v("hot async-node"),
"cache",
(name, src, dist) => {
createCacheCase(name, src, dist, "async-node");
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export default 1;
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ it("should store and resume asset parser and generator states", async () => {
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname
context: __dirname,
experiments: {
cache: {
type: "persistent"
}
}
};

1 comment on commit d0393f1

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on d0393f1 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-12-27 170b877) Current Change
10000_big_production-mode_disable-minimize + exec 37.9 s ± 592 ms 38.1 s ± 543 ms +0.62 %
10000_development-mode + exec 1.86 s ± 25 ms 1.83 s ± 25 ms -1.90 %
10000_development-mode_hmr + exec 682 ms ± 12 ms 681 ms ± 24 ms -0.14 %
10000_production-mode + exec 2.5 s ± 32 ms 2.47 s ± 40 ms -1.15 %
arco-pro_development-mode + exec 1.76 s ± 46 ms 1.76 s ± 45 ms +0.06 %
arco-pro_development-mode_hmr + exec 377 ms ± 0.82 ms 376 ms ± 0.72 ms -0.10 %
arco-pro_production-mode + exec 3.62 s ± 91 ms 3.61 s ± 75 ms -0.19 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.67 s ± 53 ms 3.69 s ± 124 ms +0.43 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.62 s ± 114 ms 3.68 s ± 112 ms +1.54 %
threejs_development-mode_10x + exec 1.51 s ± 11 ms 1.52 s ± 20 ms +0.14 %
threejs_development-mode_10x_hmr + exec 790 ms ± 33 ms 769 ms ± 5.9 ms -2.73 %
threejs_production-mode_10x + exec 5.4 s ± 129 ms 5.38 s ± 183 ms -0.30 %
10000_big_production-mode_disable-minimize + rss memory 9505 MiB ± 278 MiB 9526 MiB ± 101 MiB +0.22 %
10000_development-mode + rss memory 653 MiB ± 10.9 MiB 691 MiB ± 21.2 MiB +5.94 %
10000_development-mode_hmr + rss memory 1451 MiB ± 170 MiB 1428 MiB ± 464 MiB -1.57 %
10000_production-mode + rss memory 628 MiB ± 25.7 MiB 664 MiB ± 33.4 MiB +5.70 %
arco-pro_development-mode + rss memory 578 MiB ± 26.7 MiB 592 MiB ± 36.7 MiB +2.55 %
arco-pro_development-mode_hmr + rss memory 610 MiB ± 104 MiB 642 MiB ± 109 MiB +5.16 %
arco-pro_production-mode + rss memory 731 MiB ± 44.6 MiB 741 MiB ± 56.5 MiB +1.40 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 745 MiB ± 71.9 MiB 760 MiB ± 32.2 MiB +1.92 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 759 MiB ± 30.2 MiB 751 MiB ± 35.3 MiB -0.98 %
threejs_development-mode_10x + rss memory 594 MiB ± 12.2 MiB 632 MiB ± 29 MiB +6.30 %
threejs_development-mode_10x_hmr + rss memory 1171 MiB ± 171 MiB 1194 MiB ± 156 MiB +2.02 %
threejs_production-mode_10x + rss memory 873 MiB ± 52.4 MiB 923 MiB ± 40.5 MiB +5.69 %

Please sign in to comment.