forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
356 lines (315 loc) · 15.5 KB
/
Copy pathbenchmarks.yml
File metadata and controls
356 lines (315 loc) · 15.5 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
name: Foundry Benchmarks
permissions: {}
on:
workflow_dispatch:
inputs:
versions:
description: "Comma-separated list of Foundry versions to benchmark (optional, defaults to 'master,local'). Include 'local' to compare this branch's HEAD against a source-built 'origin/master' baseline and post the comparison on the PR. Omit 'local' (e.g. 'stable,nightly') to track released versions and commit results."
required: false
type: string
repos:
description: "Comma-separated repos to benchmark. Each entry: org/repo[:rev]. This override applies to every suite, so extra arguments must be valid for test, build, and coverage. Leave empty to use the per-suite defaults."
required: false
type: string
env:
DEFAULT_VERSIONS: "master,local"
RUSTC_WRAPPER: "sccache"
jobs:
run-benchmarks:
name: Run All Benchmarks
runs-on: depot-ubuntu-24.04-32
permissions:
contents: read
pull-requests: read
outputs:
is_source_comparison: ${{ steps.prep.outputs.is_source_comparison }}
# Source-built baseline/candidate use the profiling profile, forge only.
env:
FOUNDRY_BENCH_LOCAL_BUILD_PROFILE: profiling
FOUNDRY_BENCH_LOCAL_BUILD_BINS: forge
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
# Full history so the origin/master baseline can be built from source.
fetch-depth: 0
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config z3
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
with:
toolchain: stable
- uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 # v1
- uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
- name: Setup Foundry
env:
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
GITHUB_WORKSPACE: ${{ github.workspace }}
run: |
./.github/scripts/setup-foundryup.sh
printf '%s\n' "$GITHUB_WORKSPACE/.foundry/bin" >> "$GITHUB_PATH"
- name: Build benchmark binary
run: cargo build --locked --release --bin foundry-bench
- name: Install hyperfine
run: |
curl -L https://github.com/sharkdp/hyperfine/releases/download/v1.19.0/hyperfine-v1.19.0-x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo mv hyperfine-v1.19.0-x86_64-unknown-linux-gnu/hyperfine /usr/local/bin/
rm -rf hyperfine-v1.19.0-x86_64-unknown-linux-gnu
# When 'local' is requested, build origin/master from source in a separate
# worktree and benchmark it as the baseline (labelled 'master') against
# this branch (labelled 'local'). This compares against master itself, not
# the last stable release, so master-only regressions are not hidden.
- name: Prepare comparison
id: prep
env:
GH_TOKEN: ${{ github.token }}
REQUESTED_VERSIONS: ${{ github.event.inputs.versions || env.DEFAULT_VERSIONS }}
run: |
compact="${REQUESTED_VERSIONS//[[:space:]]/}"
if [[ ",$compact," == *,local,* ]]; then
git fetch --no-tags origin master:refs/remotes/origin/master
base_sha="$(git rev-parse origin/master)"
candidate_sha="$(git rev-parse HEAD)"
git worktree add --detach ../foundry-baseline "$base_sha"
echo "versions=master=../foundry-baseline,local" >> "$GITHUB_OUTPUT"
echo "is_source_comparison=true" >> "$GITHUB_OUTPUT"
printf '%s' "$base_sha" > benches/baseline-ref.txt
printf '%s' "$candidate_sha" > benches/candidate-ref.txt
git rev-list --count "${candidate_sha}..${base_sha}" > benches/behind-count.txt
pr_number=$(gh api --method GET "repos/$GITHUB_REPOSITORY/pulls" \
-f "head=$GITHUB_REPOSITORY_OWNER:$GITHUB_REF_NAME" -f state=open \
--jq '.[0].number // empty')
if [[ -n "$pr_number" ]]; then
echo "BENCHMARK_PR_NUMBER=$pr_number" >> "$GITHUB_ENV"
fi
echo "Comparing origin/master ($base_sha) against this branch."
else
echo "versions=$REQUESTED_VERSIONS" >> "$GITHUB_OUTPUT"
echo "is_source_comparison=false" >> "$GITHUB_OUTPUT"
fi
- name: Run forge test benchmarks
env:
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
VERSIONS: ${{ steps.prep.outputs.versions }}
REPOS: ${{ github.event.inputs.repos }}
run: |
benches/scripts/run-benchmark-suite.sh ci test \
--versions "$VERSIONS" --output-dir ./benches --repos "$REPOS"
- name: Run forge isolate test benchmarks
env:
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
VERSIONS: ${{ steps.prep.outputs.versions }}
REPOS: ${{ github.event.inputs.repos }}
run: |
benches/scripts/run-benchmark-suite.sh ci isolate \
--versions "$VERSIONS" --output-dir ./benches --repos "$REPOS"
# Temporarily disabled as long as the previous stable benchmark baseline
# does not support symbolic execution.
# - name: Run forge symbolic benchmarks
# env:
# FOUNDRY_DIR: ${{ github.workspace }}/.foundry
# VERSIONS: ${{ github.event.inputs.versions || env.DEFAULT_VERSIONS }}
# REPOS: ${{ github.event.inputs.repos }}
# run: |
# benches/scripts/run-benchmark-suite.sh ci symbolic \
# --versions "$VERSIONS" --output-dir ./benches --repos "$REPOS"
- name: Run forge build benchmarks
env:
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
VERSIONS: ${{ steps.prep.outputs.versions }}
REPOS: ${{ github.event.inputs.repos }}
run: |
benches/scripts/run-benchmark-suite.sh ci build \
--versions "$VERSIONS" --output-dir ./benches --repos "$REPOS"
- name: Run forge coverage benchmarks
env:
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
VERSIONS: ${{ steps.prep.outputs.versions }}
REPOS: ${{ github.event.inputs.repos }}
run: |
benches/scripts/run-benchmark-suite.sh ci coverage \
--versions "$VERSIONS" --output-dir ./benches --repos "$REPOS"
- name: Combine benchmark results
run: ./.github/scripts/combine-benchmarks.sh benches
- name: Print benchmark results
run: cat benches/LATEST.md
# For a source comparison the bench binary writes one JSON summary per
# version (suffixed `-master` / `-local`). Merge each side's per-benchmark
# files into a single baseline/candidate summary for the verdict table.
- name: Merge benchmark JSON summaries
if: steps.prep.outputs.is_source_comparison == 'true'
run: |
shopt -s nullglob
base_parts=( benches/*_bench-master.json )
cand_parts=( benches/*_bench-local.json )
if [[ ${#base_parts[@]} -eq 0 || ${#cand_parts[@]} -eq 0 ]]; then
echo "::error::Missing per-version benchmark JSON summaries."
exit 1
fi
jq -s 'add' "${base_parts[@]}" > benches/base-summary.json
jq -s 'add' "${cand_parts[@]}" > benches/candidate-summary.json
- name: Build benchmark manifest
if: steps.prep.outputs.is_source_comparison == 'true'
run: |
shopt -s nullglob
manifests=( benches/*_bench-manifest.json )
if [[ ${#manifests[@]} -eq 0 ]]; then
echo "::error::Missing benchmark suite manifests."
exit 1
fi
python3 .github/scripts/benchmark_clickhouse.py manifest \
--output benches/benchmark-manifest.json \
--baseline "$(cat benches/baseline-ref.txt)" \
--candidate "$(cat benches/candidate-ref.txt)" \
"${manifests[@]}"
- name: Upload benchmark results as artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: benchmark-results
# The symbolic benchmark artifact is omitted while the symbolic step is disabled.
# base/candidate summaries and baseline-ref exist only for source comparisons.
path: |
benches/forge_test_bench.md
benches/forge_isolate_test_bench.md
benches/forge_build_bench.md
benches/forge_coverage_bench.md
benches/LATEST.md
benches/base-summary.json
benches/candidate-summary.json
benches/common/
benches/benchmark-manifest.json
benches/baseline-ref.txt
benches/candidate-ref.txt
benches/behind-count.txt
publish-results:
name: Publish Results
needs: run-benchmarks
runs-on: ubuntu-latest
# All git writes happen here, on a clean ubuntu-latest runner that has
# never executed third-party benchmark code.
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository # zizmor: ignore[artipacked] persists credentials to push benchmark data
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: true
- name: Download benchmark results
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: benchmark-results
path: benches/
- name: Commit benchmark results
id: commit_results
if: needs.run-benchmarks.outputs.is_source_comparison != 'true'
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
run: ./.github/scripts/commit-benchmark-results.sh benches "${{ github.event_name }}" "${{ github.repository }}"
- name: Create PR for manual runs
if: github.event_name == 'workflow_dispatch' && steps.commit_results.outputs.committed == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
BRANCH_NAME: ${{ steps.commit_results.outputs.branch_name }}
with:
script: |
const branchName = process.env.BRANCH_NAME;
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'chore(bench): update benchmark results',
head: branchName,
base: 'master',
body: `## Benchmark Results Update
This PR contains the latest benchmark results from a manual workflow run.
---
🤖 This PR was automatically generated by the [Foundry Benchmarks workflow](https://github.com/${{ github.repository }}/actions).`
});
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
- name: Comment on PR
if: needs.run-benchmarks.outputs.is_source_comparison == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
REQUESTED_REPOS: ${{ github.event.inputs.repos || 'per-benchmark defaults' }}
REQUESTED_VERSIONS: ${{ github.event.inputs.versions || env.DEFAULT_VERSIONS }}
with:
script: |
const { execFileSync } = require('child_process');
const fs = require('fs');
const branch = context.ref.replace('refs/heads/', '');
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branch}`,
state: 'open',
});
if (prs.length === 0) {
console.log(`No open PR found for branch '${branch}', skipping comment.`);
return;
}
const pr = prs[0];
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const baseline = fs.readFileSync('benches/baseline-ref.txt', 'utf8').trim();
const candidate = fs.readFileSync('benches/candidate-ref.txt', 'utf8').trim();
const behind = Number(fs.readFileSync('benches/behind-count.txt', 'utf8').trim());
const repoUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}`;
const baselineLabel = '[`master`](' + repoUrl + '/commit/' + baseline + ')';
const candidateLabel = '[`' + pr.head.ref + '`](' + repoUrl + '/commit/' + candidate + ')';
const verdicts = execFileSync(
'./.github/scripts/compare-nightly.sh',
['benches/base-summary.json', 'benches/candidate-summary.json', '2', '2'],
{
env: {
...process.env,
BASE_LABEL: baselineLabel,
CANDIDATE_LABEL: candidateLabel,
REPORT_TITLE: '',
FAIL_ON_REGRESSION: '0',
},
},
).toString();
const formatted = execFileSync(
'./.github/scripts/format-pr-comment.sh',
['benches/LATEST.md'],
).toString();
const warnings = [];
if (behind > 0) {
const noun = behind === 1 ? 'commit' : 'commits';
warnings.push(`> ⚠️ Candidate is [**${behind} ${noun} behind \`master\`**](${repoUrl}/compare/${candidate}...${baseline}). Consider rebasing for accurate results.`);
}
if (pr.head.sha !== candidate) {
warnings.push(`> ⚠️ This report measured ${candidateLabel}, but the PR has since advanced to \`${pr.head.sha.slice(0, 12)}\`.`);
}
const warningBlock = warnings.length ? `\n${warnings.join('\n')}\n` : '';
const marker = '<!-- foundry-bench-report:foundry-bench -->';
const legend = '> Lower is better · ❌ regression (≥2%) · ✅ improvement (≤−2%) · ⚪ within 2%';
const body = `${marker}\ncc @${pr.user.login}\n\n✅ Benchmark complete! [View workflow run](${runUrl})\n\n## Benchmark Results\n\n### Configuration\n- Versions: ${baselineLabel} vs ${candidateLabel}\n- Workflow input: \`versions=${process.env.REQUESTED_VERSIONS}; repos=${process.env.REQUESTED_REPOS}\`\n${warningBlock}\n${verdicts}\n${legend}\n\n${formatted}\n\n---\n\n🤖 Generated by the [Foundry Benchmarks workflow](${repoUrl}/actions/workflows/benchmarks.yml).`;
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
per_page: 100,
});
const existing = comments.find(comment =>
comment.user?.type === 'Bot' && comment.body?.includes(marker),
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
console.log(`Updated benchmark results on PR #${pr.number}`);
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body,
});
console.log(`Posted benchmark results to PR #${pr.number}`);
}