-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (131 loc) · 4.87 KB
/
benchmark.yml
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:
workflow_dispatch: # Manual triggering with options
inputs:
force-run:
description: 'Force benchmarks to run'
required: true
type: boolean
default: false
push:
branches: [ "master" ]
paths:
- 'src/**/*.rs'
# Only run on changes that could affect performance
- '!src/tests/**'
- 'benches/**/*.rs'
# Only consider direct dependency changes
- 'Cargo.toml'
- '.github/workflows/benchmark.yml'
pull_request:
types: [opened, synchronize, reopened]
branches: [ "master" ]
paths:
- 'src/**/*.rs'
- '!src/tests/**'
- 'benches/**/*.rs'
- 'Cargo.toml'
- '.github/workflows/benchmark.yml'
# Add concurrency to cancel outdated runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
# Add required permissions for commenting on PRs if we want to post results
pull-requests: write
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.check.outputs.should-run }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for git diff
# Get default branch name
- name: Get default branch name
id: default-branch
run: |
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
echo "name=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
- name: Fetch all branches
run: |
git fetch --all
git branch -a
- id: check
name: Check if benchmarks are needed
run: |
DEFAULT_BRANCH="${{ steps.default-branch.outputs.name }}"
echo "Default branch is: $DEFAULT_BRANCH"
echo "Current ref is: ${{ github.ref }}"
echo "Event type is: ${{ github.event_name }}"
# Manual trigger check
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.force-run }}" == "true" ]]; then
echo "Manual run requested with force-run=true"
echo "should-run=true" >> $GITHUB_OUTPUT
exit 0
fi
# Get list of changed files
if [[ "${{ github.ref }}" == "refs/heads/$DEFAULT_BRANCH" ]]; then
echo "On default branch, comparing with previous commit"
if git rev-parse HEAD^ >/dev/null 2>&1; then
git diff --name-only HEAD^ HEAD > changes.txt
else
git ls-files > changes.txt
fi
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "On PR, comparing with default branch"
git diff --name-only origin/$DEFAULT_BRANCH... > changes.txt
else
echo "On feature branch, comparing with default branch"
git diff --name-only origin/$DEFAULT_BRANCH... > changes.txt
fi
echo "Changed files:"
cat changes.txt
# Check for performance-critical changes
if grep -q "src/lib.rs\|src/parser.rs\|src/packet.rs" changes.txt; then
echo "Core functionality changed"
echo "should-run=true" >> $GITHUB_OUTPUT
elif grep -q "^benches/" changes.txt; then
echo "Benchmark code changed"
echo "should-run=true" >> $GITHUB_OUTPUT
elif grep -q "Cargo.toml" changes.txt && grep -q "^\[dependencies\]" Cargo.toml; then
echo "Dependencies changed"
echo "should-run=true" >> $GITHUB_OUTPUT
else
echo "No performance-critical changes"
echo "should-run=false" >> $GITHUB_OUTPUT
fi
benchmark:
needs: check-changes
if: needs.check-changes.outputs.should-run == 'true'
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
# Only run full benchmarks on master or if explicitly requested
- name: Run quick benchmarks
if: github.ref != 'refs/heads/master' && github.event_name != 'workflow_dispatch'
run: |
# Run with fewer samples for PR checks
cargo bench --workspace -- --warm-up-time 1 --measurement-time 2 --sample-size 10
cargo bench --workspace --features="async" -- --warm-up-time 1 --measurement-time 2 --sample-size 10
- name: Run full benchmarks
if: github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch'
run: |
cargo bench --workspace
cargo bench --workspace --features="async"
- name: Store benchmark result
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: target/criterion/**/*.json
retention-days: 30