|
| 1 | +name: Performance Benchmark |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + deployments: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: benchmark-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +env: |
| 19 | + PHP_VERSION: '8.3' |
| 20 | + BENCHMARK_DOCS: 10000 |
| 21 | + BENCHMARK_DIMS: 128 |
| 22 | + |
| 23 | +jobs: |
| 24 | + # ───────────────────────────────────────────────────────────────────────────── |
| 25 | + # PR Benchmark: Compare PR against base branch |
| 26 | + # ───────────────────────────────────────────────────────────────────────────── |
| 27 | + benchmark-pr: |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + name: PR Performance Comparison |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout PR branch |
| 34 | + uses: actions/checkout@v5 |
| 35 | + with: |
| 36 | + path: pr |
| 37 | + |
| 38 | + - name: Checkout base branch |
| 39 | + uses: actions/checkout@v5 |
| 40 | + with: |
| 41 | + ref: ${{ github.base_ref }} |
| 42 | + path: base |
| 43 | + |
| 44 | + - name: Setup PHP |
| 45 | + uses: shivammathur/setup-php@v2 |
| 46 | + with: |
| 47 | + php-version: ${{ env.PHP_VERSION }} |
| 48 | + coverage: none |
| 49 | + ini-values: memory_limit=1G |
| 50 | + |
| 51 | + - name: Cache Composer packages (PR) |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: pr/vendor |
| 55 | + key: ${{ runner.os }}-php-${{ hashFiles('pr/**/composer.lock') }} |
| 56 | + |
| 57 | + - name: Cache Composer packages (base) |
| 58 | + uses: actions/cache@v4 |
| 59 | + with: |
| 60 | + path: base/vendor |
| 61 | + key: ${{ runner.os }}-php-${{ hashFiles('base/**/composer.lock') }} |
| 62 | + |
| 63 | + - name: Install dependencies |
| 64 | + run: | |
| 65 | + composer install --prefer-dist --no-progress --no-dev --working-dir=pr |
| 66 | + composer install --prefer-dist --no-progress --no-dev --working-dir=base |
| 67 | +
|
| 68 | + - name: Run benchmark on base branch |
| 69 | + run: | |
| 70 | + php base/benchmark/run.php \ |
| 71 | + --profile=ci \ |
| 72 | + --scenarios=small \ |
| 73 | + --documents=${{ env.BENCHMARK_DOCS }} \ |
| 74 | + --dimensions=${{ env.BENCHMARK_DIMS }} \ |
| 75 | + --github-bench=base-benchmark.json |
| 76 | + continue-on-error: true |
| 77 | + |
| 78 | + - name: Run benchmark on PR branch |
| 79 | + run: | |
| 80 | + php pr/benchmark/run.php \ |
| 81 | + --profile=ci \ |
| 82 | + --scenarios=small \ |
| 83 | + --documents=${{ env.BENCHMARK_DOCS }} \ |
| 84 | + --dimensions=${{ env.BENCHMARK_DIMS }} \ |
| 85 | + --github-bench=pr-benchmark.json |
| 86 | +
|
| 87 | + - name: Compare benchmarks |
| 88 | + uses: openpgpjs/github-action-pull-request-benchmark@v1 |
| 89 | + with: |
| 90 | + name: PHPVector Performance |
| 91 | + tool: customBiggerIsBetter |
| 92 | + pr-benchmark-file-path: pr-benchmark.json |
| 93 | + base-benchmark-file-path: base-benchmark.json |
| 94 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 95 | + comment-on-alert: true |
| 96 | + alert-threshold: '90%' |
| 97 | + fail-on-alert: false |
| 98 | + fail-threshold: '80%' |
| 99 | + |
| 100 | + - name: Upload benchmark artifacts |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: benchmark-results-pr |
| 104 | + path: | |
| 105 | + pr-benchmark.json |
| 106 | + base-benchmark.json |
| 107 | + retention-days: 14 |
| 108 | + |
| 109 | + # ───────────────────────────────────────────────────────────────────────────── |
| 110 | + # Main Benchmark: Store historical data and update graphs |
| 111 | + # ───────────────────────────────────────────────────────────────────────────── |
| 112 | + benchmark-main: |
| 113 | + if: github.ref == 'refs/heads/main' |
| 114 | + runs-on: ubuntu-latest |
| 115 | + name: Store Benchmark History |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout |
| 119 | + uses: actions/checkout@v5 |
| 120 | + |
| 121 | + - name: Setup PHP |
| 122 | + uses: shivammathur/setup-php@v2 |
| 123 | + with: |
| 124 | + php-version: ${{ env.PHP_VERSION }} |
| 125 | + coverage: none |
| 126 | + ini-values: memory_limit=1G |
| 127 | + |
| 128 | + - name: Cache Composer packages |
| 129 | + uses: actions/cache@v4 |
| 130 | + with: |
| 131 | + path: vendor |
| 132 | + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} |
| 133 | + |
| 134 | + - name: Install dependencies |
| 135 | + run: composer install --prefer-dist --no-progress --no-dev |
| 136 | + |
| 137 | + - name: Run benchmark |
| 138 | + run: | |
| 139 | + php benchmark/run.php \ |
| 140 | + --profile=ci \ |
| 141 | + --scenarios=small \ |
| 142 | + --documents=${{ env.BENCHMARK_DOCS }} \ |
| 143 | + --dimensions=${{ env.BENCHMARK_DIMS }} \ |
| 144 | + --github-bench=benchmark-results.json |
| 145 | +
|
| 146 | + - name: Store benchmark result |
| 147 | + uses: benchmark-action/github-action-benchmark@v1 |
| 148 | + with: |
| 149 | + name: PHPVector Performance |
| 150 | + tool: customBiggerIsBetter |
| 151 | + output-file-path: benchmark-results.json |
| 152 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 153 | + auto-push: true |
| 154 | + benchmark-data-dir-path: docs/benchmark |
| 155 | + comment-on-alert: true |
| 156 | + alert-threshold: '150%' |
| 157 | + fail-on-alert: false |
| 158 | + |
| 159 | + - name: Upload benchmark artifact |
| 160 | + uses: actions/upload-artifact@v4 |
| 161 | + with: |
| 162 | + name: benchmark-results-main |
| 163 | + path: benchmark-results.json |
| 164 | + retention-days: 90 |
0 commit comments