|
| 1 | +# Runs criterion benchmarks across the workspace and publishes results to |
| 2 | +# GitHub Pages for tracking performance regressions over time. |
| 3 | +name: Benchmarks |
| 4 | + |
| 5 | +on: |
| 6 | + # Only runs on main branch pushes (not on every PR) because benchmarks |
| 7 | + # take longer and are primarily useful for trend analysis. |
| 8 | + push: |
| 9 | + branches: ["main"] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + # Required by `github-action-benchmark` to push results to gh-pages. |
| 18 | + contents: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + bench: |
| 22 | + name: Run benchmarks |
| 23 | + runs-on: ubuntu-latest |
| 24 | + timeout-minutes: 30 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v6.0.2 |
| 27 | + with: |
| 28 | + # Full history is needed for benchmark comparison across commits. |
| 29 | + fetch-depth: 0 |
| 30 | + - name: Install Rust nightly |
| 31 | + shell: pwsh |
| 32 | + run: rustup toolchain install nightly --profile minimal |
| 33 | + |
| 34 | + - name: Restore cargo registry and git cache |
| 35 | + uses: actions/cache@v5.0.5 |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.cargo/registry/index/ |
| 39 | + ~/.cargo/registry/cache/ |
| 40 | + ~/.cargo/git/db/ |
| 41 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-cargo-registry- |
| 44 | +
|
| 45 | + - name: Restore workspace target cache |
| 46 | + uses: actions/cache@v5.0.5 |
| 47 | + with: |
| 48 | + path: target |
| 49 | + key: ${{ runner.os }}-bench-target-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} |
| 50 | + restore-keys: | |
| 51 | + ${{ runner.os }}-bench-target- |
| 52 | +
|
| 53 | + # Build first without running so the benchmark step is purely measurement. |
| 54 | + - name: Build benchmarks |
| 55 | + run: cargo bench --workspace --benches --no-run |
| 56 | + |
| 57 | + # `continue-on-error` keeps the workflow alive even if a benchmark fails, |
| 58 | + # so previous results are not overwritten by a single broken benchmark. |
| 59 | + # `--output-format bencher` produces machine-readable output for the |
| 60 | + # benchmark storage action. |
| 61 | + - name: Run benchmarks |
| 62 | + continue-on-error: true |
| 63 | + run: cargo bench --workspace --benches -- --output-format bencher 2>&1 | tee target/benchmarks.txt |
| 64 | + |
| 65 | + - name: Upload criterion HTML reports |
| 66 | + uses: actions/upload-artifact@v7.0.1 |
| 67 | + with: |
| 68 | + name: criterion-reports-${{ github.sha }} |
| 69 | + path: target/criterion/ |
| 70 | + if-no-files-found: ignore |
| 71 | + |
| 72 | + # Publishes benchmark results to the `gh-pages` branch so they can be |
| 73 | + # viewed as a trend chart over time. |
| 74 | + - name: Store benchmark results |
| 75 | + uses: benchmark-action/github-action-benchmark@v1.22.0 |
| 76 | + with: |
| 77 | + tool: cargo |
| 78 | + output-file-path: target/benchmarks.txt |
| 79 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + auto-push: true |
| 81 | + gh-pages-branch: gh-pages |
| 82 | + benchmark-data-dir-path: benchmarks |
| 83 | + comment-on-alert: true |
| 84 | + # Alert if performance degrades by more than 150% from baseline. |
| 85 | + alert-threshold: "150%" |
| 86 | + fail-on-alert: false |
0 commit comments