-
Notifications
You must be signed in to change notification settings - Fork 7
181 lines (145 loc) Β· 6.52 KB
/
perfcheck.yml
File metadata and controls
181 lines (145 loc) Β· 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Benchmarks
on:
pull_request:
branches: [main]
paths-ignore:
- 'documentation/**'
- 'README.md'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
benchmark:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Find merge-base and prepare worktrees
id: setup
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
MERGE_BASE=$(git merge-base HEAD origin/${{ github.event.pull_request.base.ref }})
echo "merge_base=$MERGE_BASE" >> $GITHUB_OUTPUT
# Create worktrees for base and head
git worktree add ../base $MERGE_BASE
git worktree add ../head HEAD
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0
with:
shared-key: benchmark
workspaces: |
../base -> target
../head -> target
- name: Install hyperfine
run: |
wget https://github.com/sharkdp/hyperfine/releases/download/v1.18.0/hyperfine_1.18.0_amd64.deb
sudo dpkg -i hyperfine_1.18.0_amd64.deb
- name: Build Yarn (base)
working-directory: ../base
run: cargo build --release -p zpm --bin yarn-bin
- name: Build Yarn (head)
working-directory: ../head
run: cargo build --release -p zpm --bin yarn-bin
- name: Start mock proxy
working-directory: ../head
run: |
./target/release/yarn-bin debug mock-proxy -p 4873 https://registry.npmjs.org &
echo "YARN_NPM_REGISTRY_SERVER=http://localhost:4873" >> $GITHUB_ENV
echo "YARN_UNSAFE_HTTP_WHITELIST=localhost" >> $GITHUB_ENV
- name: Run benchmark cold (base)
working-directory: ../base
run: ./target/release/yarn-bin debug bench gatsby install-full-cold
- name: Run benchmark cold (head)
working-directory: ../head
run: ./target/release/yarn-bin debug bench gatsby install-full-cold
- name: Run benchmark warm with lockfile (base)
working-directory: ../base
run: ./target/release/yarn-bin debug bench gatsby install-cache-and-lock
- name: Run benchmark warm with lockfile (head)
working-directory: ../head
run: ./target/release/yarn-bin debug bench gatsby install-cache-and-lock
- name: Generate benchmark comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const readResults = (mode) => {
const base = JSON.parse(fs.readFileSync(`../base/bench-gatsby-${mode}.json`, 'utf8'));
const head = JSON.parse(fs.readFileSync(`../head/bench-gatsby-${mode}.json`, 'utf8'));
return {base, head};
};
const formatTime = (t) => `${t.toFixed(3)}s`;
const formatDiff = (pct) => {
const num = parseFloat(pct);
if (num > 0) return `+${pct}% β οΈ`;
if (num < 0) return `${pct}% β
`;
return `${pct}%`;
};
const formatPct = (base, head) => (((head - base) / base) * 100).toFixed(2);
const benches = [
{mode: 'install-full-cold', label: 'gatsby install-full-cold'},
{mode: 'install-cache-and-lock', label: 'gatsby install-cache-and-lock (warm, with lockfile)'},
];
const mergedResults = {
benchmarks: benches.map(({mode, label}) => {
const {base, head} = readResults(mode);
base.results.forEach(r => {
r.command = `[base][${mode}] ${r.command.split('/').pop()}`;
});
head.results.forEach(r => {
r.command = `[head][${mode}] ${r.command.split('/').pop()}`;
});
return {
benchmark: label,
mode,
results: [...base.results, ...head.results],
};
}),
};
fs.writeFileSync('bench-merged.json', JSON.stringify(mergedResults, null, 2));
const renderSection = ({mode, label}) => {
const {base, head} = readResults(mode);
const baseStats = base.results[0];
const headStats = head.results[0];
const meanPct = formatPct(baseStats.mean, headStats.mean);
const medianPct = formatPct(baseStats.median, headStats.median);
return `### ${label}
| Metric | Base | Head | Difference |
|--------|------|------|------------|
| **Mean** | ${formatTime(baseStats.mean)} | ${formatTime(headStats.mean)} | ${formatDiff(meanPct)} |
| **Median** | ${formatTime(baseStats.median)} | ${formatTime(headStats.median)} | ${formatDiff(medianPct)} |
| **Min** | ${formatTime(baseStats.min)} | ${formatTime(headStats.min)} | |
| **Max** | ${formatTime(baseStats.max)} | ${formatTime(headStats.max)} | |
| **Std Dev** | ${formatTime(baseStats.stddev)} | ${formatTime(headStats.stddev)} | |
<details>
<summary>π Raw benchmark data (${label})</summary>
**Base times:** ${baseStats.times.map(t => formatTime(t)).join(', ')}
**Head times:** ${headStats.times.map(t => formatTime(t)).join(', ')}
</details>`;
};
const sections = benches.map(renderSection).join('\n\n---\n\n');
const comment = `## β±οΈ Benchmark Results
${sections}
`.split('\n').map(l => l.trim()).join('\n');
// Save comment body and PR number for the perfcheck-comment workflow
fs.mkdirSync('perfcheck-comment', { recursive: true });
fs.writeFileSync('perfcheck-comment/comment-body.md', comment);
fs.writeFileSync('perfcheck-comment/pr-number.txt', String(context.issue.number));
- name: Upload comment body artifact
uses: actions/upload-artifact@v4
with:
name: perfcheck-comment
path: perfcheck-comment/
- name: Upload merged benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: bench-merged.json