-
Notifications
You must be signed in to change notification settings - Fork 153
148 lines (124 loc) · 4.59 KB
/
benchmark.yaml
File metadata and controls
148 lines (124 loc) · 4.59 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
name: Benchmark
on:
pull_request:
branches:
- main
paths:
- "src/**"
- "benches/**"
- "Cargo.toml"
- "Cargo.lock"
permissions:
contents: read
pull-requests: write
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
benchmark:
runs-on: ubuntu-24.04
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Install stable toolchain
run: rustup update stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-bench-
- name: Run benchmarks on PR branch
run: |
cargo bench --bench e2e_body_forwarding -- --noplot --save-baseline pr
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
clean: false
- name: Run benchmarks on main branch
run: |
cargo bench --bench e2e_body_forwarding -- --noplot --save-baseline main
- name: Checkout PR branch again for comparison
uses: actions/checkout@v4
with:
clean: false
- name: Install critcmp
run: cargo install critcmp
- name: Compare benchmarks
id: compare
run: |
echo "## Benchmark Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
critcmp main pr >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Check for regressions > 10% by parsing critcmp output
# critcmp outputs factors like 1.15x for 15% slower, we check for factors > 1.10
COMPARISON=$(critcmp main pr --threshold 10 2>&1 || true)
# Look for lines where pr is slower than main (factor > 1.10 in the comparison)
REGRESSION=$(echo "$COMPARISON" | awk -F',' 'NR>1 && $5 > 1.10 {print}')
if [ -n "$REGRESSION" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "## ⚠️ Performance Regression Detected (>10%)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "$REGRESSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "regression=true" >> $GITHUB_OUTPUT
echo "$REGRESSION"
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ No significant performance regression detected." >> $GITHUB_STEP_SUMMARY
echo "regression=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = process.env.GITHUB_STEP_SUMMARY;
// Read the step summary
const summaryContent = fs.readFileSync(summary, 'utf8');
const body = `### 📊 Benchmark Comparison
${summaryContent}
<details>
<summary>Benchmark Details</summary>
- Baseline: \`main\` branch
- Comparison: This PR
- Threshold: 10% regression triggers warning
</details>`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Benchmark Comparison')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
- name: Fail if regression detected
if: steps.compare.outputs.regression == 'true'
run: |
echo "Performance regression >10% detected!"
exit 1