8000 Report performance in CI (#5488) · rollup/rollup@82ec9b4 · GitHub
[go: up one dir, main page]

Skip to content
10BC0

Commit 82ec9b4

Browse files
authored
Report performance in CI (#5488)
* Report performance in CI * Include the report of executing perf-report/index.js * Remove all ANSI styles * Report added or removed tree-shaking stages
1 parent db19272 commit 82ec9b4

File tree

5 files changed

+265
-18
lines changed

5 files changed

+265
-18
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Performance Report
2+
env:
3+
BUILD_BOOTSTRAP_CJS: mv dist dist-build && node dist-build/bin/rollup --config rollup.config.ts --configPlugin typescript --configTest --forceExit && rm -rf dist-build
4+
5+
on:
6+
pull_request:
7+
types:
8+
- synchronize
9+
- opened
10+
- reopened
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
build-artefacts:
21+
strategy:
22+
matrix:
23+
settings:
24+
- name: current
25+
ref: refs/pull/${{ github.event.number }}/merge
26+
- name: previous
27+
ref: ${{github.event.pull_request.base.ref}}
28+
name: Build ${{matrix.settings.name}} artefact
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout Commit
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{matrix.settings.ref}}
35+
- name: Install Toolchain
36+
uses: dtolnay/rust-toolchain@stable
37+
with:
38+
toolchain: nightly-2023-10-05
39+
targets: x86_64-unknown-linux-gnu
40+
- name: Cache cargo
41+
uses: actions/cache@v4
42+
with:
43+
path: |
44+
~/.cargo/registry/index/
45+
~/.cargo/registry/cache/
46+
~/.cargo/git/db/
47+
.cargo-cache
48+
rust/target/
49+
key: cargo-cache-${{ hashFiles('rust/Cargo.lock') }}
50+
restore-keys: cargo-cache
51+
- name: Setup Node
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: 18
55+
- name: Cache Node Modules
56+
id: cache-node-modules
57+
uses: actions/cache@v4
58+
with:
59+
path: node_modules
60+
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
61+
- name: Install dependencies
62+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
63+
run: npm ci --ignore-scripts
64+
- name: Build artefacts 123
65+
run: npm exec -- concurrently -c green,blue 'npm:build:napi -- --release' 'npm:build:cjs' && npm run build:copy-native && ${{env.BUILD_BOOTSTRAP_CJS}} && npm run build:copy-native
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: ${{ matrix.settings.name }}
70+
path: dist/
71+
if-no-files-found: error
72+
73+
report:
74+
needs: build-artefacts
75+
permissions:
76+
pull-requests: write
77+
runs-on: ubuntu-latest
78+
name: Report Performance
79+
steps:
80+
- name: Checkout Commit
81+
uses: actions/checkout@v4
82+
with:
83+
ref: refs/pull/${{ github.event.number }}/merge
84+
- name: Install Toolchain
85+
uses: dtolnay/rust-toolchain@stable
86+
with:
87+
toolchain: nightly-2023-10-05
88+
targets: x86_64-unknown-linux-gnu
89+
- name: Cache cargo
90+
uses: actions/cache@v4
91+
with:
92+
path: |
93+
~/.cargo/registry/index/
94+
~/.cargo/registry/cache/
95+
~/.cargo/git/db/
96+
.cargo-cache
97+
rust/target/
98+
key: cargo-cache-${{ hashFiles('rust/Cargo.lock') }}
99+
restore-keys: cargo-cache
100+
- name: Setup Node
101+
uses: actions/setup-node@v4
102+
with:
103+
node-version: 18
104+
- name: Cache Node Modules
105+
id: cache-node-modules
106+
uses: actions/cache@v4
107+
with:
108+
path: node_modules
109+
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
110+
- name: Install dependencies
111+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
112+
run: npm ci --ignore-scripts
113+
- name: Download all artifacts
114+
uses: actions/download-artifact@v4
115+
with:
116+
path: _benchmark
117+
- name: Change rollup import in internal benchmark
118+
run: |
119+
echo "export { rollup as previousRollup, VERSION as previousVersion } from '../../_benchmark/previous/rollup.js';" > ./scripts/perf-report/rollup-artefacts.js
120+
echo "export { rollup as newRollup } from '../../_benchmark/current/rollup.js';" >> ./scripts/perf-report/rollup-artefacts.js
121+
- name: Run internal benchmark
122+
run: node --expose-gc scripts/perf-report/index.js
123+
- name: Install benchmark tool
124+
run: cargo install --locked hyperfine
125+
- name: Run Rough benchmark
126+
run: |
127+
hyperfine --warmup 1 --export-markdown _benchmark/rough-report.md --show-output --runs 3 \
128+
'node _benchmark/previous/bin/rollup -i ./perf/entry.js -o _benchmark/result/previous.js' \
129+
'node _benchmark/current/bin/rollup -i ./perf/entry.js -o _benchmark/result/current.js'
130+
- name: Combine bechmark reports
131+
run: |
132+
echo "# Performance report!" > _benchmark/result.md
133+
echo "## Rough benchmark" >> _benchmark/result.md
134+
cat _benchmark/rough-report.md >> _benchmark/result.md
135+
echo "## Internal benchmark" >> _benchmark/result.md
136+
cat _benchmark/internal-report.md >> _benchmark/result.md
137+
- name: Find Performance report
138+
uses: peter-evans/find-comment@v3
139+
id: findPerformanceReport
140+
with:
141+
issue-number: ${{ github.event.number }}
142+
comment-author: 'github-actions[bot]'
143+
body-includes: 'Performance report'
144+
- name: Create or update Performance report
145+
uses: peter-evans/create-or-update-comment@v4
146+
id: createOrUpdatePerformanceReport
147+
with:
148+
comment-id: ${{ steps.findPerformanceReport.outputs.comment-id }}
149+
issue-number: ${{ github.event.number }}
150+
edit-mode: replace
151+
body-path: _benchmark/result.md

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"lint:markdown:nofix": "prettier --check \"**/*.md\"",
6767
"lint:rust": "cd rust && cargo fmt && cargo clippy --fix --allow-dirty",
6868
"lint:rust:nofix": "cd rust && cargo fmt --check && cargo clippy",
69-
"perf": "npm run build && node --expose-gc scripts/perf.js",
69+
"perf": "npm run build && node --expose-gc scripts/perf-report/index.js",
7070
"prepare": "husky && node scripts/check-release.js || npm run build:prepare",
7171
"prepublishOnly": "node scripts/check-release.js && node scripts/prepublish.js",
7272
"postpublish": "node scripts/postpublish.js",
Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { chdir } from 'node:process';
55
import { fileURLToPath } from 'node:url';
66
import { createColors } from 'colorette';
77
import prettyBytes from 'pretty-bytes';
8-
import { rollup as previousRollup, VERSION as previousVersion } from 'rollup';
9-
// eslint-disable-next-line import/no-unresolved
10-
import { rollup as newRollup } from '../dist/rollup.js';
11-
import { runWithEcho } from './helpers.js';
8+
import { runWithEcho } from '../helpers.js';
9+
import reportCollector from './report-collector.js';
10+
import { newRollup, previousRollup, previousVersion } from './rollup-artefacts.js';
1211

1312
/**
1413
* @typedef {Record<string,{memory:number,time:number}>} CollectedTimings
@@ -18,7 +17,7 @@ import { runWithEcho } from './helpers.js';
1817
* @typedef {Record<string, [number, number, number][]>} AccumulatedTimings
1918
*/
2019

21-
const PERF_DIRECTORY = new URL('../perf/', import.meta.url);
20+
const PERF_DIRECTORY = new URL('../../perf/', import.meta.url);
2221
const ENTRY = new URL('entry.js', PERF_DIRECTORY);
2322
const THREEJS_COPIES = 10;
2423
const { bold, underline, cyan, red, green } = createColors();
@@ -91,10 +90,12 @@ async function calculatePrintAndPersistTimings() {
9190
);
9291
clearLines(numberOfLinesToClear);
9392
}
93+
reportCollector.startRecord();
9494
printMeasurements(
9595
getAverage(accumulatedNewTimings, RUNS_TO_AVERAGE),
9696
getAverage(accumulatedPreviousTimings, RUNS_TO_AVERAGE)
9797
);
98+
await reportCollector.outputMsg();
9899
}
99100

100101
/**
@@ -172,9 +173,16 @@ function getSingleAverage(times, runs, discarded) {
172173
* @return {number}
173174
*/
174175
function printMeasurements(newAverage, previousAverage, filter = /.*/) {
175-
const printedLabels = Object.keys(newAverage).filter(label => filter.test(label));
176-
console.info('');
177-
for (const label of printedLabels) {
176+
const newPrintedLabels = Object.keys(newAverage).filter(predicateLabel);
177+
const previousPrintedLabels = Object.keys(previousAverage).filter(predicateLabel);
178+
179+
const newTreeShakings = newPrintedLabels.filter(isTreeShakingLabel);
180+
const oldTreeShakings = previousPrintedLabels.filter(isTreeShakingLabel);
181+
182+
const addedTreeShaking = newTreeShakings.length - oldTreeShakings.length;
183+
let treeShakingCount = 0;
184+
185+
for (const label of newPrintedLabels) {
178186
/**
179187
* @type {function(string): string}
180188
*/
@@ -185,16 +193,54 @@ function printMeasurements(newAverage, previousAverage, filter = /.*/) {
185193
color = underline;
186194
}
187195
}
188-
console.info(
189-
color(
190-
`${label}: ${getFormattedTime(
191-
newAverage[label].time,
192-
previousAverage[label]?.time
193-
)}, ${getFormattedMemory(newAverage[label].memory, previousAverage[label]?.memory)}`
194-
)
195-
);
196+
const texts = [];
197+
if (isTreeShakingLabel(label)) {
198+
treeShakingCount++;
199+
if (addedTreeShaking < 0 && treeShakingCount === newTreeShakings.length) {
200+
texts.push(generateSingleReport(label));
201+
for (const label of oldTreeShakings.slice(addedTreeShaking)) {
202+
const { time, memory } = previousAverage[label];
203+
texts.push(`${label}: ${time.toFixed(0)}ms, ${prettyBytes(memory)}, removed stage`);
204+
}
205+
} else if (addedTreeShaking > 0 && treeShakingCount > oldTreeShakings.length) {
206+
texts.push(generateSingleReport(label, ', new stage'));
207+
} else {
208+
texts.push(generateSingleReport(label));
209+
}
210+
} else {
211+
texts.push(generateSingleReport(label));
212+
}
213+
for (const text of texts) {
214+
reportCollector.push(text);
215+
console.info(color(text));
216+
}
217+
}
218+
return Math.max(newPrintedLabels.length, previousPrintedLabels.length) + 2;
219+
220+
/**
221+
* @param {string} label
222+
*/
223+
function predicateLabel(label) {
224+
return filter.test(label);
225+
}
226+
227+
/**
228+
* @param {string} label
229+
* @param {string} addon
230+
*/
231+
function generateSingleReport(label, addon = '') {
232+
return `${label}: ${getFormattedTime(
233+
newAverage[label].time,
234+
previousAverage[label]?.time
235+
)}, ${getFormattedMemory(newAverage[label].memory, previousAverage[label]?.memory)}${addon}`;
196236
}
197-
return printedLabels.length + 2;
237+
}
238+
239+
/**
240+
* @param {string} label
241+
*/
242+
function isTreeShakingLabel(label) {
243+
return label.startsWith('treeshaking pass');
198244
}
199245

200246
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { writeFile } from 'node:fs/promises';
2+
import { fileURLToPath } from 'node:url';
3+
4+
export default new (class ReportCollector {
5+
/**
6+
* @type {string[]}
7+
*/
8+
#messageList = [];
9+
#isRecording = false;
10+
startRecord() {
11+
this.#isRecording = true;
12+
}
13+
/**
14+
* @param {string} message
15+
*/
16+
push(message) {
17+
if (!this.#isRecording) return;
18+
if (message.startsWith('#')) {
19+
message = '##' + message;
20+
}
21+
this.#messageList.push(message);
22+
}
23+
outputMsg() {
24+
if (process.env.CI) {
25+
return writeFile(
26+
fileURLToPath(new URL('../../_benchmark/internal-report.md', import.meta.url)),
27+
removeAnsiStyles(this.#messageList.join('\n'))
28+
);
29+
}
30+
}
31+
})();
32+
33+
/**
34+
* @param {string} text
35+
* @returns {string}
36+
*/
37+
function removeAnsiStyles(text) {
38+
const ansiRegex = new RegExp(
39+
[
40+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
41+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
42+
].join('|'),
43+
'g'
44+
);
45+
46+
return text.replace(ansiRegex, '');
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { rollup as previousRollup, VERSION as previousVersion } from 'rollup';
2+
// eslint-disable-next-line import/no-unresolved
3+
export { rollup as newRollup } from '../../dist/rollup.js';

0 commit comments

Comments
 (0)
0