Skip to content

Commit c23f098

Browse files
authored
Zero-Copy Body Conversion and Performance Benchmarks (#627)
1 parent cf6875c commit c23f098

9 files changed

Lines changed: 878 additions & 4 deletions

File tree

.config/nextest.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ store-failure-output = true
113113
test-threads = 1
114114

115115
[profile.ci]
116-
inherits = "test"
117116
# Print out output for failing tests as soon as they fail, and also at the end
118117
# of the run (for easy scrollability).
119118
failure-output = "immediate-final"

.github/workflows/benchmark.yaml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Benchmark
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- "src/**"
9+
- "benches/**"
10+
- "Cargo.toml"
11+
- "Cargo.lock"
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
env:
18+
CARGO_TERM_COLOR: always
19+
CARGO_INCREMENTAL: 0
20+
21+
jobs:
22+
benchmark:
23+
runs-on: ubuntu-24.04
24+
steps:
25+
- name: Checkout PR branch
26+
uses: actions/checkout@v4
27+
28+
- name: Install stable toolchain
29+
run: rustup update stable
30+
31+
- name: Cache cargo registry
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cargo/registry
36+
~/.cargo/git
37+
target
38+
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
39+
restore-keys: |
40+
${{ runner.os }}-cargo-bench-
41+
42+
- name: Run benchmarks on PR branch
43+
run: |
44+
cargo bench --bench e2e_body_forwarding -- --noplot --save-baseline pr
45+
46+
- name: Checkout main branch
47+
uses: actions/checkout@v4
48+
with:
49+
ref: main
50+
clean: false
51+
52+
- name: Run benchmarks on main branch
53+
run: |
54+
cargo bench --bench e2e_body_forwarding -- --noplot --save-baseline main
55+
56+
- name: Checkout PR branch again for comparison
57+
uses: actions/checkout@v4
58+
with:
59+
clean: false
60+
61+
- name: Install critcmp
62+
run: cargo install critcmp
63+
64+
- name: Compare benchmarks
65+
id: compare
66+
run: |
67+
echo "## Benchmark Results" >> $GITHUB_STEP_SUMMARY
68+
echo "" >> $GITHUB_STEP_SUMMARY
69+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
70+
critcmp main pr >> $GITHUB_STEP_SUMMARY
71+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
72+
73+
# Check for regressions > 10%
74+
REGRESSION=$(critcmp main pr --threshold 10 --filter-by-regression 2>&1 || true)
75+
if [ -n "$REGRESSION" ] && [ "$REGRESSION" != "group,benchmark,main,pr,factor" ]; then
76+
echo "" >> $GITHUB_STEP_SUMMARY
77+
echo "## ⚠️ Performance Regression Detected (>10%)" >> $GITHUB_STEP_SUMMARY
78+
echo "" >> $GITHUB_STEP_SUMMARY
79+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
80+
echo "$REGRESSION" >> $GITHUB_STEP_SUMMARY
81+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
82+
echo "regression=true" >> $GITHUB_OUTPUT
83+
echo "$REGRESSION"
84+
else
85+
echo "" >> $GITHUB_STEP_SUMMARY
86+
echo "✅ No significant performance regression detected." >> $GITHUB_STEP_SUMMARY
87+
echo "regression=false" >> $GITHUB_OUTPUT
88+
fi
89+
90+
- name: Comment on PR
91+
uses: actions/github-script@v7
92+
with:
93+
script: |
94+
const fs = require('fs');
95+
const summary = process.env.GITHUB_STEP_SUMMARY;
96+
97+
// Read the step summary
98+
const summaryContent = fs.readFileSync(summary, 'utf8');
99+
100+
const body = `### 📊 Benchmark Comparison
101+
102+
${summaryContent}
103+
104+
<details>
105+
<summary>Benchmark Details</summary>
106+
107+
- Baseline: \`main\` branch
108+
- Comparison: This PR
109+
- Threshold: 10% regression triggers warning
110+
111+
</details>`;
112+
113+
// Find existing comment
114+
const { data: comments } = await github.rest.issues.listComments({
115+
owner: context.repo.owner,
116+
repo: context.repo.repo,
117+
issue_number: context.issue.number,
118+
});
119+
120+
const botComment = comments.find(comment =>
121+
comment.user.type === 'Bot' &&
122+
comment.body.includes('📊 Benchmark Comparison')
123+
);
124+
125+
if (botComment) {
126+
await github.rest.issues.updateComment({
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
comment_id: botComment.id,
130+
body: body
131+
});
132+
} else {
133+
await github.rest.issues.createComment({
134+
owner: context.repo.owner,
135+
repo: context.repo.repo,
136+
issue_number: context.issue.number,
137+
body: body
138+
});
139+
}
140+
141+
- name: Fail if regression detected
142+
if: steps.compare.outputs.regression == 'true'
143+
run: |
144+
echo "Performance regression >10% detected!"
145+
exit 1

0 commit comments

Comments
 (0)