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
name: Benchmarks
on:
push:
branches:
pull_request:
branches:
permissions:
contents: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
jobs:
benchmark:
name: Performance Regression Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
- name: Run benchmarks
run: cargo bench --bench parsing -- --noplot --save-baseline current
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./target/criterion
key: ${{ runner.os }}-criterion-${{ github.base_ref || 'main' }}
restore-keys: |
${{ runner.os }}-criterion-
- name: Compare with baseline (PR only)
if: github.event_name == 'pull_request'
run: |
if [ -d "./target/criterion" ]; then
echo "## Benchmark Comparison" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Comparing against baseline from \`${{ github.base_ref }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Run comparison
cargo bench --bench parsing -- --noplot --baseline main 2>&1 | tee bench_output.txt || true
# Extract regression info
if grep -q "regressed" bench_output.txt; then
echo "### ⚠️ Performance Regressions Detected" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
grep -A 2 "regressed" bench_output.txt >> $GITHUB_STEP_SUMMARY || true
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
else
echo "### ✅ No Performance Regressions" >> $GITHUB_STEP_SUMMARY
fi
fi
- name: Save benchmark baseline (main only)
if: github.ref == 'refs/heads/main'
run: |
cargo bench --bench parsing -- --noplot --save-baseline main
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: target/criterion
retention-days: 30
# Optional: Track benchmarks over time with GitHub Pages
benchmark-report:
name: Publish Benchmark Report
runs-on: ubuntu-latest
needs: benchmark
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download benchmark results
uses: actions/download-artifact@v4
with:
name: benchmark-results
path: target/criterion
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Generate HTML report
run: |
cargo bench --bench parsing -- --noplot
mkdir -p ./bench-report
cp -r target/criterion/* ./bench-report/ || true
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./bench-report
destination_dir: benchmarks
keep_files: true