Performance benchmark on a big network, posted on every PR

scripts/perf-bench.js times routing, a game day, an action, panels, the
NOC dashboard and the map on tests/fixtures/big-network.json (104 POPs,
950 PNIs, 832 caches), base and head in alternating turns, and says
whether routing results changed. perf.yml runs it on every PR against
the base; perf-comment.yml posts the table as one updated comment.
New performance skill, CLAUDE.md rule, PR template and docs.
This commit is contained in:
Frederic Jung 2026-10-26 06:39:23 +01:00
parent ad8b1bebcb
commit 308c3f7045
No known key found for this signature in database
13 changed files with 322 additions and 1 deletions

15
.github/pull_request_template.md vendored Normal file
View file

@ -0,0 +1,15 @@
<!-- One small feature or one fix per pull request, please. See CONTRIBUTING.md. -->
## What and why
## How it was tested
<!-- Tests added or changed, and what you checked by hand (phone width, both orientations, Italian). -->
## Performance
<!-- Changes to site/ must show their performance on a big network. The Performance check posts the
numbers as a comment on this PR. Locally:
git show origin/main:site/index.html > /tmp/base.html
npm run perf -- --base /tmp/base.html
Explain anything marked slower. -->

40
.github/workflows/perf-comment.yml vendored Normal file
View file

@ -0,0 +1,40 @@
name: Performance comment
# Posts the table from the Performance workflow on its pull request, and updates the same comment on every push.
# Runs in this repository's context with write access, so it only reads the uploaded text and never runs PR code.
on:
workflow_run:
workflows: [Performance]
types: [completed]
permissions:
pull-requests: write
issues: write
actions: read
jobs:
comment:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: perf
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post or update the comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
pr=$(tr -cd '0-9' < pr-number.txt)
[ -n "$pr" ] || { echo "no PR number"; exit 0; }
# Trust the number only if that PR's head is the commit that was benchmarked.
head=$(gh api "repos/$REPO/pulls/$pr" --jq .head.sha)
[ "$head" = "$HEAD_SHA" ] || { echo "PR #$pr has moved on since this run"; exit 0; }
{ echo '<!-- perf-bench -->'; head -c 60000 perf.md; } > body.md
id=$(gh api "repos/$REPO/issues/$pr/comments" --paginate --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("<!-- perf-bench -->"))) | .id' | head -n 1)
if [ -n "$id" ]; then gh api -X PATCH "repos/$REPO/issues/comments/$id" -F body=@body.md > /dev/null
else gh api -X POST "repos/$REPO/issues/$pr/comments" -F body=@body.md > /dev/null; fi
echo "Posted to #$pr"

50
.github/workflows/perf.yml vendored Normal file
View file

@ -0,0 +1,50 @@
name: Performance
# Times the PR against its base on a very large network and uploads the table. A separate workflow
# (perf-comment.yml) posts it on the PR: runs for pull requests from forks have no write access.
on:
pull_request:
paths:
- 'site/**'
- 'scripts/perf-*.js'
- 'tests/fixtures/**'
- 'tests/harness.js'
workflow_dispatch:
permissions:
contents: read
jobs:
bench:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- name: Base version of the game
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
git fetch --depth=1 origin "$BASE_SHA"
git show FETCH_HEAD:site/index.html > "$RUNNER_TEMP/base.html"
echo "BASE_ARG=--base $RUNNER_TEMP/base.html" >> "$GITHUB_ENV"
- name: Benchmark
run: node scripts/perf-bench.js $BASE_ARG --md perf.md --summary "$GITHUB_STEP_SUMMARY"
- name: Remember the PR number
if: github.event_name == 'pull_request'
env:
PR: ${{ github.event.pull_request.number }}
run: echo "$PR" > pr-number.txt
- uses: actions/upload-artifact@v4
if: github.event_name == 'pull_request'
with:
name: perf
path: |
perf.md
pr-number.txt
retention-days: 7