-
Notifications
You must be signed in to change notification settings - Fork 50
Add automated benchmark regression check in CI (#144) #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prajwal-tech07
wants to merge
1
commit into
mllam:main
Choose a base branch
from
prajwal-tech07:feat/ci-benchmark-regression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+561
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Automated benchmark regression check (PR vs base branch). | ||
| # | ||
| # Design (see https://github.com/mllam/weather-model-graphs/issues/144): | ||
| # * Run the scaling benchmark twice, back-to-back, on the SAME runner: once | ||
| # against the PR's install of the library and once against the base branch's | ||
| # install. Only the library under test is swapped - the benchmark harness | ||
| # itself always comes from the PR checkout (the package uses a src/ layout, | ||
| # so the working tree never shadows the installed library). | ||
| # * Compare RELATIVE (%) change, not absolute seconds, so per-runner noise | ||
| # largely cancels. | ||
| # * Post the result as a single, updating ("sticky") PR comment. The check is | ||
| # informational and NON-BLOCKING for now; the threshold starts low and can | ||
| # be raised once the runner's real noise floor is known. | ||
|
|
||
| name: benchmark regression | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "src/weather_model_graphs/create/**" | ||
| - "tests/benchmarks/**" | ||
| - ".github/workflows/benchmark-regression.yml" | ||
| workflow_dispatch: | ||
|
|
||
| # Only the latest run per PR needs to finish; cancel superseded runs. | ||
| concurrency: | ||
| group: benchmark-regression-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| benchmark: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| env: | ||
| # Kept small so the whole job stays within a few minutes. Tune here. | ||
| BENCH_ARGS: "--min-N 50 --max-N 200 --num-steps 4 --archetype keisler" | ||
| # Start low; raise once we've seen the runner's noise floor across a few | ||
| # real runs (per the discussion on #144). | ||
| THRESHOLD_PCT: "0.1" | ||
| BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }} | ||
| steps: | ||
| - name: Checkout PR | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v6 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Run benchmark on PR and base, then compare | ||
| run: | | ||
| set -euo pipefail | ||
| uv venv | ||
| source .venv/bin/activate | ||
|
|
||
| echo "::group::Install PR build and benchmark it" | ||
| uv pip install ".[visualisation]" | ||
| python -m tests.benchmarks.graph_creation_scaling $BENCH_ARGS \ | ||
| --output-json pr.json --output-plot-runtime pr_plot.png | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::Swap in the '$BASE_REF' library and benchmark it" | ||
| # Reinstall ONLY the library from the base branch; the harness on disk | ||
| # (the PR's) is untouched, so we measure with one fixed ruler. | ||
| uv pip install --reinstall-package weather-model-graphs \ | ||
| "weather-model-graphs @ git+https://github.com/mllam/weather-model-graphs.git@${BASE_REF}" | ||
| python -m tests.benchmarks.graph_creation_scaling $BENCH_ARGS \ | ||
| --output-json base.json --output-plot-runtime base_plot.png | ||
| echo "::endgroup::" | ||
|
|
||
| python -m tests.benchmarks.compare base.json pr.json \ | ||
| --threshold-pct "$THRESHOLD_PCT" \ | ||
| --baseline-label "$BASE_REF" --contender-label "PR" \ | ||
| --output comment.md | ||
|
|
||
| - name: Publish result to the job summary | ||
| if: always() | ||
| run: cat comment.md >> "$GITHUB_STEP_SUMMARY" || true | ||
|
|
||
| - name: Post or update sticky PR comment | ||
| # Only same-repo PRs get a writable token; fork PRs fall back to the job | ||
| # summary above. Never fail the job over the comment (informational). | ||
| if: github.event_name == 'pull_request' | ||
| continue-on-error: true | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const marker = '<!-- benchmark-regression-check -->'; | ||
| const body = fs.readFileSync('comment.md', 'utf8'); | ||
| const { owner, repo } = context.repo; | ||
| const issue_number = context.issue.number; | ||
| const comments = await github.paginate( | ||
| github.rest.issues.listComments, | ||
| { owner, repo, issue_number, per_page: 100 } | ||
| ); | ||
| const existing = comments.find( | ||
| (c) => c.body && c.body.includes(marker) | ||
| ); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner, repo, comment_id: existing.id, body, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner, repo, issue_number, body, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use https://github.com/marocchino/sticky-pull-request-comment here instead