|
| 1 | +name: Benchmark PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + branches: [ master ] |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +env: |
| 13 | + BENCHMARK_DISABLE_JEMALLOC: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + benchmark-delta: |
| 17 | + name: Comparison |
| 18 | + runs-on: [self-hosted, linux] |
| 19 | + continue-on-error: true |
| 20 | + timeout-minutes: 60 |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout Code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + submodules: recursive |
| 28 | + |
| 29 | + - run: sudo apt-get update |
| 30 | + - uses: awalsh128/cache-apt-pkgs-action@latest |
| 31 | + with: |
| 32 | + packages: librocksdb-dev libzstd-dev libbz2-dev liblz4-dev |
| 33 | + |
| 34 | + - uses: aws-actions/configure-aws-credentials@v4 |
| 35 | + with: |
| 36 | + aws-region: us-east-2 |
| 37 | + |
| 38 | + - name: Cache SPM |
| 39 | + uses: runs-on/cache@v4 |
| 40 | + with: |
| 41 | + path: '**/.build' |
| 42 | + key: ${{ runner.os }}-spm-release-${{ hashFiles('**/Package.resolved') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-spm-release- |
| 45 | + env: |
| 46 | + RUNS_ON_S3_BUCKET_CACHE: laminar-gh-action-cache |
| 47 | + |
| 48 | + - name: Cache Cargo |
| 49 | + uses: actions/cache@v4 |
| 50 | + with: |
| 51 | + path: | |
| 52 | + ~/.cargo/bin/ |
| 53 | + ~/.cargo/registry/index/ |
| 54 | + ~/.cargo/registry/cache/ |
| 55 | + ~/.cargo/git/db/ |
| 56 | + target/ |
| 57 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 58 | + |
| 59 | + - name: Cache bandersnatch_vrfs static lib |
| 60 | + uses: actions/cache@v4 |
| 61 | + with: |
| 62 | + path: .lib/libbandersnatch_vrfs.a |
| 63 | + key: ${{ runner.os }}-libs-libbandersnatch-${{ hashFiles('Utils/Sources/bandersnatch/**') }} |
| 64 | + restore-keys: | |
| 65 | + ${{ runner.os }}-libs-libbandersnatch |
| 66 | +
|
| 67 | + - name: Cache bls static lib |
| 68 | + uses: actions/cache@v4 |
| 69 | + with: |
| 70 | + path: .lib/libbls.a |
| 71 | + key: ${{ runner.os }}-libs-libbls-${{ hashFiles('Utils/Sources/bls/**') }} |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-libs-libbls |
| 74 | +
|
| 75 | + - name: Cache erasure-coding static lib |
| 76 | + uses: actions/cache@v4 |
| 77 | + with: |
| 78 | + path: .lib/libec.a |
| 79 | + key: ${{ runner.os }}-libs-libec-${{ hashFiles('Utils/Sources/erasure-coding/**') }} |
| 80 | + restore-keys: | |
| 81 | + ${{ runner.os }}-libs-libec |
| 82 | +
|
| 83 | + - name: Setup Swift |
| 84 | + uses: SwiftyLab/setup-swift@latest |
| 85 | + |
| 86 | + - name: Setup Rust |
| 87 | + uses: dtolnay/rust-toolchain@nightly |
| 88 | + with: |
| 89 | + components: rustfmt |
| 90 | + |
| 91 | + - name: Build dependencies |
| 92 | + run: make deps |
| 93 | + |
| 94 | + - name: Check if benchmarks exist and setup environment |
| 95 | + run: | |
| 96 | + [ -d "JAMTests/Benchmarks" ] && echo "hasBenchmark=1" >> $GITHUB_ENV |
| 97 | +
|
| 98 | + - name: Switch to branch 'master' |
| 99 | + if: ${{ env.hasBenchmark == '1' }} |
| 100 | + run: | |
| 101 | + git checkout master |
| 102 | +
|
| 103 | + - name: Run benchmarks for branch 'master' |
| 104 | + if: ${{ env.hasBenchmark == '1' }} |
| 105 | + run: | |
| 106 | + cd JAMTests |
| 107 | + # Check if benchmarks exist on master and if the benchmark plugin is available |
| 108 | + if [ -d "Benchmarks" ] && swift package plugin --list 2>/dev/null | grep -q benchmark; then |
| 109 | + swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update master --no-progress --quiet |
| 110 | + else |
| 111 | + echo "Benchmarks don't exist on master branch yet or benchmark plugin not available - skipping master baseline" |
| 112 | + fi |
| 113 | +
|
| 114 | + - name: Switch to PR branch |
| 115 | + if: ${{ env.hasBenchmark == '1' }} |
| 116 | + run: | |
| 117 | + git checkout ${{ github.head_ref }} |
| 118 | +
|
| 119 | + - name: Run benchmarks for PR branch |
| 120 | + if: ${{ env.hasBenchmark == '1' }} |
| 121 | + run: | |
| 122 | + cd JAMTests |
| 123 | + swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request --no-progress --quiet |
| 124 | +
|
| 125 | + - name: Compare PR and master |
| 126 | + if: ${{ env.hasBenchmark == '1' }} |
| 127 | + id: benchmark |
| 128 | + run: | |
| 129 | + cd JAMTests |
| 130 | + echo "# 📊 Benchmark Results" |
| 131 | + echo "Generated on: $(date)" |
| 132 | + echo "" |
| 133 | + echo "exitStatus=1" >> $GITHUB_ENV |
| 134 | +
|
| 135 | + # Check if master baseline exists for comparison |
| 136 | + if [ -f ".benchmarkBaselines/BenchmarkTestVectors/master/results.json" ]; then |
| 137 | + echo "## 🔄 Comparison with Master Branch" |
| 138 | + echo "" |
| 139 | + swift package benchmark baseline check master pull_request --format markdown |
| 140 | + echo "exitStatus=0" >> $GITHUB_ENV |
| 141 | + else |
| 142 | + echo "## 🆕 First Benchmark Run" |
| 143 | + echo "" |
| 144 | + echo "⚠️ Master baseline not found. This appears to be the first benchmark run." |
| 145 | + echo "The following results will become the baseline for future comparisons:" |
| 146 | + echo "" |
| 147 | +
|
| 148 | + # Run benchmarks to generate results for first time |
| 149 | + echo "### Benchmark Results:" |
| 150 | + swift package benchmark --format markdown 2>&1 || true |
| 151 | + echo "exitStatus=0" >> $GITHUB_ENV |
| 152 | + fi |
| 153 | + continue-on-error: true |
| 154 | + |
| 155 | + - name: Exit with correct status |
| 156 | + if: ${{ env.hasBenchmark == '1' }} |
| 157 | + run: | |
| 158 | + exit ${{ env.exitStatus }} |
0 commit comments