Skip to content

Commit 61f994f

Browse files
authored
Merge pull request #5 from danielebarbaro/feat/update-delete-benchmark-refactor
Benchmark
2 parents 538e224 + 9629530 commit 61f994f

File tree

11 files changed

+1756
-577
lines changed

11 files changed

+1756
-577
lines changed

.github/workflows/benchmark.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: Performance Benchmark
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request_target:
7+
branches: [main]
8+
9+
permissions:
10+
contents: write
11+
issues: write
12+
pull-requests: 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 baseline from gh-pages
26+
# ─────────────────────────────────────────────────────────────────────────────
27+
benchmark-pr:
28+
if: github.event_name == 'pull_request_target'
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+
ref: ${{ github.event.pull_request.head.sha }}
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ env.PHP_VERSION }}
42+
coverage: none
43+
ini-values: memory_limit=2G
44+
45+
- name: Cache Composer packages
46+
uses: actions/cache@v5
47+
with:
48+
path: vendor
49+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
50+
51+
- name: Install dependencies
52+
run: composer install --prefer-dist --no-progress --no-dev
53+
54+
- name: Detect benchmark profile
55+
id: profile
56+
run: |
57+
SCENARIOS="xs,small"
58+
if ${{ contains(github.event.pull_request.labels.*.name, 'benchmark-full') }}; then
59+
SCENARIOS="xs,small,medium,large,highdim"
60+
fi
61+
echo "scenarios=$SCENARIOS" >> "$GITHUB_OUTPUT"
62+
63+
- name: Run benchmark
64+
run: |
65+
php benchmark/run.php \
66+
--profile=ci \
67+
--scenarios=${{ steps.profile.outputs.scenarios }} \
68+
--documents=${{ env.BENCHMARK_DOCS }} \
69+
--dimensions=${{ env.BENCHMARK_DIMS }} \
70+
--github-bench=pr-benchmark.json
71+
72+
- name: Fetch baseline from gh-pages
73+
run: |
74+
git fetch origin gh-pages --depth=1 2>/dev/null || true
75+
git show origin/gh-pages:docs/benchmark/latest.json > baseline.json 2>/dev/null || echo "[]" > baseline.json
76+
77+
- name: Compare benchmarks
78+
run: |
79+
php benchmark/compare.php \
80+
--baseline=baseline.json \
81+
--current=pr-benchmark.json \
82+
--output=comparison.md
83+
84+
- name: Post benchmark comparison
85+
if: always()
86+
uses: peter-evans/create-or-update-comment@v4
87+
with:
88+
issue-number: ${{ github.event.pull_request.number }}
89+
body-path: comparison.md
90+
edit-mode: replace
91+
92+
- name: Upload benchmark artifacts
93+
if: always()
94+
uses: actions/upload-artifact@v5
95+
with:
96+
name: benchmark-results-pr
97+
path: |
98+
pr-benchmark.json
99+
baseline.json
100+
comparison.md
101+
retention-days: 14
102+
103+
# ─────────────────────────────────────────────────────────────────────────────
104+
# Main Benchmark: Store historical data and update graphs
105+
# ─────────────────────────────────────────────────────────────────────────────
106+
benchmark-main:
107+
if: github.ref == 'refs/heads/main'
108+
runs-on: ubuntu-latest
109+
name: Store Benchmark History
110+
111+
steps:
112+
- name: Checkout
113+
uses: actions/checkout@v5
114+
115+
- name: Setup PHP
116+
uses: shivammathur/setup-php@v2
117+
with:
118+
php-version: ${{ env.PHP_VERSION }}
119+
coverage: none
120+
ini-values: memory_limit=1G
121+
122+
- name: Cache Composer packages
123+
uses: actions/cache@v5
124+
with:
125+
path: vendor
126+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
127+
128+
- name: Install dependencies
129+
run: composer install --prefer-dist --no-progress --no-dev
130+
131+
- name: Run benchmark
132+
run: |
133+
php benchmark/run.php \
134+
--profile=ci \
135+
--scenarios=small \
136+
--documents=${{ env.BENCHMARK_DOCS }} \
137+
--dimensions=${{ env.BENCHMARK_DIMS }} \
138+
--github-bench=benchmark-results.json
139+
140+
- name: Store benchmark result
141+
uses: benchmark-action/github-action-benchmark@v1
142+
with:
143+
name: PHPVector Performance
144+
tool: customBiggerIsBetter
145+
output-file-path: benchmark-results.json
146+
github-token: ${{ secrets.GITHUB_TOKEN }}
147+
auto-push: true
148+
benchmark-data-dir-path: docs/benchmark
149+
comment-on-alert: true
150+
alert-threshold: '150%'
151+
fail-on-alert: false
152+
153+
- name: Commit baseline to gh-pages
154+
run: |
155+
git fetch origin gh-pages --depth=1 2>/dev/null || true
156+
git worktree add /tmp/gh-pages gh-pages 2>/dev/null || git worktree add /tmp/gh-pages -b gh-pages
157+
mkdir -p /tmp/gh-pages/docs/benchmark
158+
cp benchmark-results.json /tmp/gh-pages/docs/benchmark/latest.json
159+
cd /tmp/gh-pages
160+
git add docs/benchmark/latest.json
161+
git diff --cached --quiet || git commit -m "Update benchmark baseline"
162+
git push origin gh-pages || true
163+
cd -
164+
git worktree remove /tmp/gh-pages
165+
166+
- name: Upload benchmark artifact
167+
uses: actions/upload-artifact@v5
168+
with:
169+
name: benchmark-results-main
170+
path: benchmark-results.json
171+
retention-days: 90

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Cache Composer packages
4040
id: composer-cache
41-
uses: actions/cache@v3
41+
uses: actions/cache@v5
4242
with:
4343
path: vendor
4444
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
@@ -58,6 +58,6 @@ jobs:
5858
run: ./vendor/bin/phpunit --coverage-clover coverage.xml
5959

6060
- name: Upload coverage to Codecov
61-
uses: codecov/codecov-action@v4
61+
uses: codecov/codecov-action@v5
6262
with:
6363
files: coverage.xml

0 commit comments

Comments
 (0)