Skip to content

Commit 843fe0e

Browse files
authored
Revert "feat: only run 1 time when not in scheduled job (#28)" (#29)
This reverts commit f6d9e69.
1 parent f6d9e69 commit 843fe0e

File tree

10 files changed

+37
-102
lines changed

10 files changed

+37
-102
lines changed

.github/workflows/scheduled_bench.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ 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
1714
- name: Build rspack
1815
run: node bin/cli.js build
1916
- name: Run benchmark

bench.config.js

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,17 @@
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-
71
export default {
82
jobs: [
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-
}
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"
6915
],
7016
rspackDirectory: process.env.RSPACK_DIR
7117
};

bin/cli.js

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

6969
const cwd = process.cwd();
7070

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

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

7978
if (!command || command === "build") {
8079
const fetchUrl = `https://github.com/${repository}`;
@@ -126,30 +125,29 @@ if (!command || command === "bench") {
126125
console.log(
127126
[
128127
`Running jobs for shard ${currentIndex}/${totalShards}:`,
129-
...shardJobs.map(job => job.name)
128+
...shardJobs
130129
].join("\n * ")
131130
);
132131

133132
for (const job of shardJobs) {
134133
const start = Date.now();
135-
const result = await run(job.name, job.runs);
136-
const message = `${job.name} was run ${job.runs} times, with the following results:`;
134+
const result = await run(job);
137135
if (isGitHubActions) {
138-
actionsCore.startGroup(message);
136+
actionsCore.startGroup(`${job} result is`);
139137
} else {
140-
console.log(message);
138+
console.log(`${job} result is`);
141139
}
142140

143141
console.log(formatResultTable(result, { verbose: true }));
144142

145143
if (isGitHubActions) {
146144
actionsCore.endGroup();
147145
const cost = Math.ceil((Date.now() - start) / 1000);
148-
console.log(`Cost for \`${job.name}\`: ${cost} s`);
146+
console.log(`Cost for \`${job}\`: ${cost} s`);
149147
}
150148

151149
await writeFile(
152-
join(benchmarkDirectory, `${job.name}.json`),
150+
join(benchmarkDirectory, `${job}.json`),
153151
JSON.stringify(result, null, 2)
154152
);
155153
}
@@ -159,5 +157,5 @@ if (!command || command === "bench") {
159157
}
160158

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

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Addon } from "./common.js";
33
export default class extends Addon {
44
async afterSetup(ctx) {
55
ctx.rspackArgs.push("--watch");
6+
ctx.runTimes = 5;
67
ctx.config =
78
ctx.config +
89
`

lib/bench.js

Lines changed: 1 addition & 3 deletions
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, runs) {
8+
export async function run(benchmarkName) {
99
const [caseName, ...addonNames] = benchmarkName.split("_");
1010
const scenario = getScenario(caseName);
1111
const addons = await Promise.all(
@@ -20,8 +20,6 @@ export async function run(benchmarkName, runs) {
2020

2121
await useAddons(addons, "beforeSetup");
2222
const ctx = await scenario.setup();
23-
ctx.runTimes = runs;
24-
2523
await useAddons(addons, "afterSetup", ctx);
2624

2725
try {

lib/compare.js

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

74-
export async function compare(base, current, benchmarkDirectory, jobs) {
74+
export async function compare(base, current, benchmarkDirectory) {
75+
const compareMetric = ["exec"];
76+
7577
const index = await fetchIndex();
7678
if (base === "latest") {
7779
base = index[index.length - 1].date;
@@ -84,20 +86,13 @@ export async function compare(base, current, benchmarkDirectory, jobs) {
8486
]);
8587
const baseData = {};
8688
const currentData = {};
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) {
89+
for (const metric of compareMetric) {
90+
for (const { name, result } of baseResults) {
9291
const tag = `${name} + ${metric}`;
9392
baseData[tag] = result[metric];
9493
}
95-
}
9694

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) {
95+
for (const { name, result } of currentResults) {
10196
const tag = `${name} + ${metric}`;
10297
currentData[tag] = result[metric];
10398
}

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)