Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

benchmark.yml

95 lines3.6 KB

1name: Benchmark
2​
3on:
4 pull_request:
5 types: [opened, synchronize, reopened, ready_for_review]
6 paths:
7 - 'packages/db/**'
8 - 'packages/db-ivm/**'
9 - 'scripts/bench/**'
10 - '.github/workflows/benchmark.yml'
11​
12 # Allows you to run this workflow manually from the Actions tab
13 workflow_dispatch:
14​
15concurrency:
16 group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
17 cancel-in-progress: true
18​
19permissions:
20 contents: read
21​
22jobs:
23 benchmark:
24 name: Incremental Update Benchmark
25 # Skip draft PRs; the benchmark runs once a PR is marked ready for review
26 # (and on subsequent pushes to it).
27 if: github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false
28 runs-on: ubuntu-latest
29 permissions:
30 contents: read
31 pull-requests: write
32 steps:
33 - name: Checkout
34 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
35 with:
36 fetch-depth: 0
37 persist-credentials: false
38 - name: Setup Tools
39 uses: tanstack/config/.github/setup@e4b48f16568324f76f467aa4c2aac2f05db632c3
40 - name: Run benchmark on PR
41 run: |
42 pnpm --filter @tanstack/db-ivm build
43 pnpm exec tsx scripts/bench/incremental-update.ts \
44 --iterations=100 --warmup=20 \
45 --outFile="$RUNNER_TEMP/candidate.json"
46 - name: Run benchmark on base
47 env:
48 BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
49 run: |
50 HEAD_SHA=$(git rev-parse HEAD)
51 BASE_SHA=$(git merge-base "origin/$BASE_REF" HEAD)
52 echo "Benchmarking base commit $BASE_SHA"
53 git checkout --force "$BASE_SHA"
54 # Run the exact same benchmark code on both sides
55 git checkout "$HEAD_SHA" -- scripts/bench
56 pnpm install --frozen-lockfile
57 pnpm --filter @tanstack/db-ivm build
58 pnpm exec tsx scripts/bench/incremental-update.ts \
59 --iterations=100 --warmup=20 \
60 --outFile="$RUNNER_TEMP/base.json"
61 - name: Compare results
62 run: |
63 pnpm exec tsx scripts/bench/compare-incremental-update.ts \
64 --base="$RUNNER_TEMP/base.json" \
65 --candidate="$RUNNER_TEMP/candidate.json" \
66 --outFile="$RUNNER_TEMP/comparison.md"
67 cat "$RUNNER_TEMP/comparison.md" >> "$GITHUB_STEP_SUMMARY"
68 - name: Upload reports
69 uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
70 with:
71 name: benchmark-reports
72 path: |
73 ${{ runner.temp }}/base.json
74 ${{ runner.temp }}/candidate.json
75 ${{ runner.temp }}/comparison.md
76 - name: Comment on PR
77 if: github.event_name == 'pull_request'
78 # PRs from forks get a read-only token; the job summary and artifacts
79 # still carry the results.
80 continue-on-error: true
81 env:
82 GH_TOKEN: ${{ github.token }}
83 PR_NUMBER: ${{ github.event.pull_request.number }}
84 REPO: ${{ github.repository }}
85 run: |
86 MARKER='<!-- incremental-update-benchmark -->'
87 BODY_FILE="$RUNNER_TEMP/comment.md"
88 { echo "$MARKER"; cat "$RUNNER_TEMP/comparison.md"; } > "$BODY_FILE"
89 COMMENT_ID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" --paginate \
90 --jq ".[] | select(.body | startswith(\"$MARKER\")) | .id" | head -n1)
91 if [ -n "$COMMENT_ID" ]; then
92 gh api -X PATCH "repos/$REPO/issues/comments/$COMMENT_ID" -F body=@"$BODY_FILE" > /dev/null
93 else
94 gh api "repos/$REPO/issues/$PR_NUMBER/comments" -F body=@"$BODY_FILE" > /dev/null
95 fi