Skip to content

Commit

Permalink
Include the report of executing perf-report/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
TrickyPi committed Apr 25, 2024
1 parent 79f768d commit d6a4f5d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 29 deletions.
41 changes: 26 additions & 15 deletions .github/workflows/performance-report.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Performance Report
env:
BUILD_BOOTSTRAP_CJS: mv dist dist-build && node dist-build/bin/rollup --config rollup.config.ts --configPlugin typescript --configTest --forceExit && rm -rf dist-build
BUILD_COMMAND_OTPION: --config rollup.config.ts --configPlugin typescript --configTest --forceExit
BUILD_BOOTSTRAP_CJS: mv dist dist-build && node dist-build/bin/rollup --config rollup.config.ts --configPlugin typescript --configTest --forceExit && rm -rf dist-build

on:
pull_request:
types:
- synchronize
- opened
- reopened
pull_request:
types:
- synchronize
- opened
- reopened

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -28,7 +27,7 @@ jobs:
ref: ${{github.event.pull_request.base.ref}}
name: Build ${{matrix.settings.name}} artefact
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout Commit
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -81,7 +80,7 @@ jobs:
- name: Checkout Commit
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.base.ref}}
ref: refs/pull/${{ github.event.number }}/merge
- name: Install Toolchain
uses: dtolnay/rust-toolchain@stable
with:
Expand Down Expand Up @@ -115,14 +114,26 @@ jobs:
uses: actions/download-artifact@v4
with:
path: _benchmark
- name: Create benchmark directory
run: mkdir -p _benchmark
- name: Change rollup import in internal benchmark
run: |
echo "export { rollup as previousRollup, VERSION as previousVersion } from '../../_benchmark/previous/rollup.js';" > ./scripts/perf-report/rollup-artefacts.js
echo "export { rollup as newRollup } from '../../_benchmark/current/rollup.js';" >> ./scripts/perf-report/rollup-artefacts.js
- name: Run internal benchmark
run: node --expose-gc scripts/perf-report/index.js
- name: Install benchmark tool
run: cargo install --locked hyperfine
- name: Run benchmark
run: hyperfine --warmup 1 --export-markdown _benchmark/result.md --show-output --runs 3 'node _benchmark/previous/bin/rollup ${{env.BUILD_COMMAND_OTPION}}' 'node _benchmark/current/bin/rollup ${{env.BUILD_COMMAND_OTPION}}'
- name: Modify benchmark result file
run: sed -i '1s;^;### Performance report!\n\n;' _benchmark/result.md
- name: Run Rough benchmark
run: |
hyperfine --warmup 1 --export-markdown _benchmark/rough-report.md --show-output --runs 3 \
'node _benchmark/previous/bin/rollup -i ./perf/entry.js -o _benchmark/result/previous.js' \
'node _benchmark/current/bin/rollup -i ./perf/entry.js -o _benchmark/result/current.js'
- name: Combine bechmark reports
run: |
echo "# Performance report!\n" > _benchmark/result.md
echo "## Rough benchmark\n" >> _benchmark/result.md
cat _benchmark/rough-report.md >> _benchmark/result.md
echo "## Internal benchmark\n" >> _benchmark/result.md
cat _benchmark/internal-report.md >> _benchmark/result.md
- name: Find Performance report
uses: peter-evans/find-comment@v3
id: findPerformanceReport
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"lint:markdown:nofix": "prettier --check \"**/*.md\"",
"lint:rust": "cd rust && cargo fmt && cargo clippy --fix --allow-dirty",
"lint:rust:nofix": "cd rust && cargo fmt --check && cargo clippy",
"perf": "npm run build && node --expose-gc scripts/perf.js",
"perf": "npm run build && node --expose-gc scripts/perf-report/index.js",
"prepare": "husky && node scripts/check-release.js || npm run build:prepare",
"prepublishOnly": "node scripts/check-release.js && node scripts/prepublish.js",
"postpublish": "node scripts/postpublish.js",
Expand Down
25 changes: 12 additions & 13 deletions scripts/perf.js → scripts/perf-report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { chdir } from 'node:process';
import { fileURLToPath } from 'node:url';
import { createColors } from 'colorette';
import prettyBytes from 'pretty-bytes';
import { rollup as previousRollup, VERSION as previousVersion } from 'rollup';
// eslint-disable-next-line import/no-unresolved
import { rollup as newRollup } from '../dist/rollup.js';
import { runWithEcho } from './helpers.js';
import { runWithEcho } from '../helpers.js';
import reportCollector from './report-collector.js';
import { newRollup, previousRollup, previousVersion } from './rollup-artefacts.js';

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

const PERF_DIRECTORY = new URL('../perf/', import.meta.url);
const PERF_DIRECTORY = new URL('../../perf/', import.meta.url);
const ENTRY = new URL('entry.js', PERF_DIRECTORY);
const THREEJS_COPIES = 10;
const { bold, underline, cyan, red, green } = createColors();
Expand Down Expand Up @@ -91,10 +90,12 @@ async function calculatePrintAndPersistTimings() {
);
clearLines(numberOfLinesToClear);
}
reportCollector.startRecord();
printMeasurements(
getAverage(accumulatedNewTimings, RUNS_TO_AVERAGE),
getAverage(accumulatedPreviousTimings, RUNS_TO_AVERAGE)
);
await reportCollector.outputMsg();
}

/**
Expand Down Expand Up @@ -185,14 +186,12 @@ function printMeasurements(newAverage, previousAverage, filter = /.*/) {
color = underline;
}
}
console.info(
color(
`${label}: ${getFormattedTime(
newAverage[label].time,
previousAverage[label]?.time
)}, ${getFormattedMemory(newAverage[label].memory, previousAverage[label]?.memory)}`
)
);
const text = `${label}: ${getFormattedTime(
newAverage[label].time,
previousAverage[label]?.time
)}, ${getFormattedMemory(newAverage[label].memory, previousAverage[label]?.memory)}`;
reportCollector.push(text);
console.info(color(text));
}
return printedLabels.length + 2;
}
Expand Down
31 changes: 31 additions & 0 deletions scripts/perf-report/report-collector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';

export default new (class ReportCollector {
/**
* @type {string[]}
*/
#messageList = [];
#isRecording = false;
startRecord() {
this.#isRecording = true;
}
/**
* @param {string} message
*/
push(message) {
if (!this.#isRecording) return;
if (message.startsWith('#')) {
message = '##' + message;
}
this.#messageList.push(message);
}
outputMsg() {
if (process.env.CI) {
return writeFile(
fileURLToPath(new URL('../../_benchmark/internal-report.md', import.meta.url)),
this.#messageList.join('\n')
);
}
}
})();
3 changes: 3 additions & 0 deletions scripts/perf-report/rollup-artefacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { rollup as previousRollup, VERSION as previousVersion } from 'rollup';
// eslint-disable-next-line import/no-unresolved
export { rollup as newRollup } from '../../dist/rollup.js';

0 comments on commit d6a4f5d

Please sign in to comment.