Skip to content

Commit f6d9e69

Browse files
authored
feat: only run 1 time when not in scheduled job (#28)
* feat: only run 1 time when not in scheduled job * feat: can config compareMetrics * feat: can config compareMetrics
1 parent a4ab1f2 commit f6d9e69

File tree

10 files changed

+102
-37
lines changed

10 files changed

+102
-37
lines changed

.github/workflows/scheduled_bench.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ jobs:
1111
- uses: actions/checkout@v4
1212
- name: Init env
1313
uses: ./.github/actions/env
14+
- name: Set Scheduled env
15+
shell: bash
16+
run: echo "SCHEDULED_JOB=true" >> $GITHUB_ENV
1417
- name: Build rspack
1518
run: node bin/cli.js build
1619
- name: Run benchmark

bench.config.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,71 @@
1+
const isScheduled = !!process.env.SCHEDULED_JOB;
2+
3+
// HMR will run 10 times in build plugin, so we should not start multiple instances of Rspack.
4+
// However, we still need to run multiple instances of Rspack when executing scheduled tasks for longer runtimes.
5+
const hmrRuns = isScheduled ? 10 : 1;
6+
17
export default {
28
jobs: [
3-
"10000_development-mode",
4-
"10000_development-mode_hmr",
5-
"10000_production-mode",
6-
"arco-pro_development-mode",
7-
"arco-pro_development-mode_intercept-plugin",
8-
"arco-pro_development-mode_hmr",
9-
"arco-pro_development-mode_hmr_intercept-plugin",
10-
"arco-pro_production-mode",
11-
"arco-pro_production-mode_intercept-plugin",
12-
"threejs_development-mode_10x",
13-
"threejs_development-mode_10x_hmr",
14-
"threejs_production-mode_10x"
9+
{
10+
name: "10000_development-mode",
11+
runs: 10,
12+
compareMetrics: ["exec"]
13+
},
14+
{
15+
name: "10000_development-mode_hmr",
16+
runs: hmrRuns,
17+
compareMetrics: ["stats"]
18+
},
19+
{
20+
name: "10000_production-mode",
21+
runs: 10,
22+
compareMetrics: ["exec"]
23+
},
24+
{
25+
name: "arco-pro_development-mode",
26+
runs: 10,
27+
compareMetrics: ["exec"]
28+
},
29+
{
30+
name: "arco-pro_development-mode_intercept-plugin",
31+
runs: 10,
32+
compareMetrics: ["exec"]
33+
},
34+
{
35+
name: "arco-pro_development-mode_hmr",
36+
runs: hmrRuns,
37+
compareMetrics: ["stats"]
38+
},
39+
{
40+
name: "arco-pro_development-mode_hmr_intercept-plugin",
41+
runs: hmrRuns,
42+
compareMetrics: ["stats"]
43+
},
44+
{
45+
name: "arco-pro_production-mode",
46+
runs: 10,
47+
compareMetrics: ["exec"]
48+
},
49+
{
50+
name: "arco-pro_production-mode_intercept-plugin",
51+
runs: 10,
52+
compareMetrics: ["exec"]
53+
},
54+
{
55+
name: "threejs_development-mode_10x",
56+
runs: 10,
57+
compareMetrics: ["exec"]
58+
},
59+
{
60+
name: "threejs_development-mode_10x_hmr",
61+
runs: hmrRuns,
62+
compareMetrics: ["stats"]
63+
},
64+
{
65+
name: "threejs_production-mode_10x",
66+
runs: 10,
67+
compareMetrics: ["exec"]
68+
}
1569
],
1670
rspackDirectory: process.env.RSPACK_DIR
1771
};

bin/cli.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ const {
6868

6969
const cwd = process.cwd();
7070

71-
const configPath = join(process.cwd(), "bench.config.js");
72-
const config = (await import(configPath)).default;
71+
const benchConfigPath = join(process.cwd(), "bench.config.js");
72+
const benchConfig = (await import(benchConfigPath)).default;
7373

74-
const jobs = config.jobs ?? [];
75-
const rspackDirectory = config.rspackDirectory ?? join(cwd, ".rspack");
76-
const benchmarkDirectory = config.benchmarkDirectory ?? join(cwd, "output");
74+
const jobs = benchConfig.jobs ?? [];
75+
const rspackDirectory = benchConfig.rspackDirectory ?? join(cwd, ".rspack");
76+
const benchmarkDirectory =
77+
benchConfig.benchmarkDirectory ?? join(cwd, "output");
7778

7879
if (!command || command === "build") {
7980
const fetchUrl = `https://github.com/${repository}`;
@@ -125,29 +126,30 @@ if (!command || command === "bench") {
125126
console.log(
126127
[
127128
`Running jobs for shard ${currentIndex}/${totalShards}:`,
128-
...shardJobs
129+
...shardJobs.map(job => job.name)
129130
].join("\n * ")
130131
);
131132

132133
for (const job of shardJobs) {
133134
const start = Date.now();
134-
const result = await run(job);
135+
const result = await run(job.name, job.runs);
136+
const message = `${job.name} was run ${job.runs} times, with the following results:`;
135137
if (isGitHubActions) {
136-
actionsCore.startGroup(`${job} result is`);
138+
actionsCore.startGroup(message);
137139
} else {
138-
console.log(`${job} result is`);
140+
console.log(message);
139141
}
140142

141143
console.log(formatResultTable(result, { verbose: true }));
142144

143145
if (isGitHubActions) {
144146
actionsCore.endGroup();
145147
const cost = Math.ceil((Date.now() - start) / 1000);
146-
console.log(`Cost for \`${job}\`: ${cost} s`);
148+
console.log(`Cost for \`${job.name}\`: ${cost} s`);
147149
}
148150

149151
await writeFile(
150-
join(benchmarkDirectory, `${job}.json`),
152+
join(benchmarkDirectory, `${job.name}.json`),
151153
JSON.stringify(result, null, 2)
152154
);
153155
}
@@ -157,5 +159,5 @@ if (!command || command === "bench") {
157159
}
158160

159161
if (!command || command === "compare") {
160-
compare(base, current, benchmarkDirectory);
162+
compare(base, current, benchmarkDirectory, jobs);
161163
}

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<title>rspack/benchmark</title>

docs/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ class BenchmarkChart {
329329
context.dataset.yAxisID === "size"
330330
? formatSize(value, value)
331331
: context.dataset.yAxisID === "ratio"
332-
? formatRatio(value, value)
333-
: formatTime(value, value);
332+
? formatRatio(value, value)
333+
: formatTime(value, value);
334334
return `${context.dataset.label}: ${text}`;
335335
}
336336
}

lib/addons/hmr.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Addon } from "./common.js";
33
export default class extends Addon {
44
async afterSetup(ctx) {
55
ctx.rspackArgs.push("--watch");
6-
ctx.runTimes = 5;
76
ctx.config =
87
ctx.config +
98
`

lib/bench.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useAddons, dirExist } from "./utils.js";
55

66
const dirname = path.resolve(fileURLToPath(import.meta.url), "..");
77

8-
export async function run(benchmarkName) {
8+
export async function run(benchmarkName, runs) {
99
const [caseName, ...addonNames] = benchmarkName.split("_");
1010
const scenario = getScenario(caseName);
1111
const addons = await Promise.all(
@@ -20,6 +20,8 @@ export async function run(benchmarkName) {
2020

2121
await useAddons(addons, "beforeSetup");
2222
const ctx = await scenario.setup();
23+
ctx.runTimes = runs;
24+
2325
await useAddons(addons, "afterSetup", ctx);
2426

2527
try {

lib/compare.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ async function getResults(date, index, benchmarkDirectory) {
7171
);
7272
}
7373

74-
export async function compare(base, current, benchmarkDirectory) {
75-
const compareMetric = ["exec"];
76-
74+
export async function compare(base, current, benchmarkDirectory, jobs) {
7775
const index = await fetchIndex();
7876
if (base === "latest") {
7977
base = index[index.length - 1].date;
@@ -86,13 +84,20 @@ export async function compare(base, current, benchmarkDirectory) {
8684
]);
8785
const baseData = {};
8886
const currentData = {};
89-
for (const metric of compareMetric) {
90-
for (const { name, result } of baseResults) {
87+
88+
for (const { name, result } of baseResults) {
89+
const job = jobs.find(job => job.name === name);
90+
const compareMetrics = job ? job.compareMetrics : [];
91+
for (const metric of compareMetrics) {
9192
const tag = `${name} + ${metric}`;
9293
baseData[tag] = result[metric];
9394
}
95+
}
9496

95-
for (const { name, result } of currentResults) {
97+
for (const { name, result } of currentResults) {
98+
const job = jobs.find(job => job.name === name);
99+
const compareMetrics = job ? job.compareMetrics : [];
100+
for (const metric of compareMetrics) {
96101
const tag = `${name} + ${metric}`;
97102
currentData[tag] = result[metric];
98103
}

lib/display.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function formatResultTable(result, { verbose, limit, threshold }) {
135135
con: l => f(l.name, l.confidence),
136136
con: l => f(l.name, l.confidence),
137137
n: l => `${l.count}`
138-
}
138+
}
139139
: undefined)
140140
};
141141
return formatTable(entries, columns);

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function runCommand(
2121
? {
2222
...process.env,
2323
...env
24-
}
24+
}
2525
: undefined
2626
});
2727
if (hasOnData) {

0 commit comments

Comments
 (0)