-
Notifications
You must be signed in to change notification settings - Fork 11
310 lines (284 loc) · 11 KB
/
Copy pathbench.yml
File metadata and controls
310 lines (284 loc) · 11 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
name: benchmark
on:
push:
branches: [main]
paths:
- "bin/katana/**"
- "crates/**"
- "!**/README.md"
pull_request:
types: [opened, synchronize, ready_for_review]
paths:
- "bin/katana/**"
- "crates/**"
- ".github/workflows/bench.yml"
- "!**/README.md"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
deployments: write
contents: write
pull-requests: write
jobs:
detect-changes:
runs-on: ubuntu-latest
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
outputs:
broader-rust: ${{ steps.filter.outputs.broader-rust }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v3
id: filter
with:
# Benchmarks don't exercise the explorer UI, so skip when the only
# changes are in crates/explorer or the submodule pointer.
filters: |
broader-rust:
- 'bin/katana/**'
- 'crates/**'
- '!crates/explorer/**'
- '.github/workflows/bench.yml'
generate-artifacts:
needs: [detect-changes]
runs-on: ubuntu-latest
if: |
needs.detect-changes.outputs.broader-rust == 'true' &&
(github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false))
container:
image: ghcr.io/dojoengine/katana-dev:latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- run: git config --global --add safe.directory "*"
- name: Restore cached artifacts
id: cache
uses: actions/cache@v4
with:
path: crates/contracts/build
key: bench-contracts-${{ hashFiles('Makefile', 'crates/contracts/build.rs', 'crates/contracts/contracts/account/**', 'crates/contracts/contracts/legacy/**', 'crates/contracts/contracts/messaging/**', 'crates/contracts/contracts/test-contracts/**', 'crates/contracts/contracts/vrf/**', 'crates/contracts/contracts/avnu/**', 'crates/contracts/contracts/openzeppelin/**', 'crates/contracts/contracts/piltover/**', 'crates/contracts/contracts/Scarb.toml') }}
- name: Build contracts
if: steps.cache.outputs.cache-hit != 'true'
run: make contracts
- name: Upload contract artifacts
uses: actions/upload-artifact@v4
with:
name: contracts
overwrite: true
retention-days: 14
if-no-files-found: error
path: crates/contracts/build
bench-codec:
needs: [detect-changes, generate-artifacts]
runs-on: ubuntu-latest
if: |
needs.detect-changes.outputs.broader-rust == 'true' &&
(github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false))
container:
image: ghcr.io/dojoengine/katana-dev:latest
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: Swatinem/rust-cache@v2
with:
key: bench-codec
- name: Download contract artifacts
uses: actions/download-artifact@v4
with:
name: contracts
path: crates/contracts/build
- name: Collect hardware specs
run: |
echo "cpu_model=$(lscpu | awk -F: '/Model name/ {gsub(/^[ \t]+/, "", $2); print $2}')" >> hw-specs.txt
echo "cpu_cores=$(nproc)" >> hw-specs.txt
echo "ram_total=$(free -h | awk '/Mem:/ {print $2}')" >> hw-specs.txt
- name: Run codec benchmarks
run: |
cargo bench -p katana-db --features arbitrary --bench codec -- --output-format bencher 2>&1 | tee raw.txt
grep '^test ' raw.txt > output.txt || true
echo "::group::Codec benchmark output"
cat output.txt
echo "::endgroup::"
if [ ! -s output.txt ]; then
echo "::error::Codec benchmark produced no results. Raw output:"
cat raw.txt
exit 1
fi
- uses: actions/upload-artifact@v4
with:
name: bench-codec
path: |
output.txt
hw-specs.txt
# bench-commit:
# runs-on: ubuntu-latest
# if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
# container:
# image: ghcr.io/dojoengine/katana-dev:latest
# steps:
# - uses: actions/checkout@v3
# - run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# - uses: Swatinem/rust-cache@v2
# with:
# key: bench-commit
#
# - name: Run commit benchmarks
# run: cargo bench -p katana-core --bench commit -- --output-format bencher | tee output.txt
#
# - uses: actions/upload-artifact@v4
# with:
# name: bench-commit
# path: output.txt
# bench-startup:
# needs: [generate-artifacts]
# runs-on: ubuntu-latest
# if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
# container:
# image: ghcr.io/dojoengine/katana-dev:latest
# steps:
# - uses: actions/checkout@v3
# - run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# - uses: Swatinem/rust-cache@v2
# with:
# key: bench-startup
#
# - name: Download contract artifacts
# uses: actions/download-artifact@v4
# with:
# name: contracts
# path: crates/contracts/build
#
# - name: Run startup benchmarks
# run: cargo bench -p katana-node-bindings --bench startup -- --output-format bencher | tee output.txt
#
# - uses: actions/upload-artifact@v4
# with:
# name: bench-startup
# path: output.txt
report:
needs: [detect-changes, bench-codec]
runs-on: ubuntu-latest
if: |
needs.detect-changes.outputs.broader-rust == 'true' &&
(github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false))
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
name: bench-codec
path: bench-results/bench-codec
- name: Merge benchmark results
run: |
cat bench-results/bench-codec/output.txt > output.txt
echo "::group::Merged benchmark output"
cat output.txt
echo "::endgroup::"
if [ ! -s output.txt ]; then
echo "::error::Benchmark output is empty"
exit 1
fi
- name: Parse hardware specs
id: hw
run: |
if [ -f bench-results/bench-codec/hw-specs.txt ]; then
cpu_model=$(grep '^cpu_model=' bench-results/bench-codec/hw-specs.txt | cut -d= -f2-)
cpu_cores=$(grep '^cpu_cores=' bench-results/bench-codec/hw-specs.txt | cut -d= -f2-)
ram_total=$(grep '^ram_total=' bench-results/bench-codec/hw-specs.txt | cut -d= -f2-)
echo "summary=**Runner:** ${cpu_model} (${cpu_cores} cores) · ${ram_total} RAM" >> "$GITHUB_OUTPUT"
else
echo "summary=Hardware specs not available" >> "$GITHUB_OUTPUT"
fi
# On push to main: update GitHub Pages with historical benchmark data
- name: Store benchmark result (main)
if: github.event_name == 'push'
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "cargo"
output-file-path: output.txt
benchmark-data-dir-path: "."
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: "130%"
comment-on-alert: true
alert-comment-cc-users: "@kariy"
# On PR: compare against main baseline and alert on regressions
- name: Compare benchmark result (PR)
if: github.event_name == 'pull_request'
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "cargo"
output-file-path: output.txt
benchmark-data-dir-path: "."
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
alert-threshold: "130%"
comment-on-alert: true
comment-always: false
alert-comment-cc-users: "@kariy"
# On PR: post a percentage-diff comment against the main baseline
- name: Fetch baseline benchmark data
if: github.event_name == 'pull_request'
run: |
git fetch origin gh-pages --depth=1 || true
git show origin/gh-pages:data.js > baseline.js 2>/dev/null || echo "window.BENCHMARK_DATA = { entries: {} };" > baseline.js
- name: Build percentage diff comment
if: github.event_name == 'pull_request'
run: node scripts/bench-percent-diff.js baseline.js output.txt diff.md
- name: Post percentage diff comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('diff.md', 'utf8');
const marker = '<!-- benchmark-percent-diff -->';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Post hardware specs comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- benchmark-hw-specs -->';
const body = `${marker}\n> ${{ steps.hw.outputs.summary }}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}