Add benchmark workflow and fix nats-core protocol benches - #974
Add benchmark workflow and fix nats-core protocol benches#974caspervonb wants to merge 4 commits into
Conversation
These encoders take bytes subjects and replies; the benches still passed str and raised TypeError, so most of bench_protocol.py failed to run. encode_sub/encode_unsub remain str, so their benches were unaffected.
Runs the nats-core benches on the base commit and the PR head on the same runner, then compares head against the same-runner baseline and fails past a regression threshold. Comparing on one machine avoids the cross-runner variance that makes microbenchmark numbers meaningless.
|
Claude finished @caspervonb's task in 2m 31s —— View job Code Review
Summary
One minor security pattern to address: two |
| run: | | ||
| uv run pytest $BENCH_PATHS \ | ||
| --benchmark-only \ | ||
| --benchmark-save=base \ |
There was a problem hiding this comment.
Using ${{ steps.refs.outputs.base }} directly in a run: script is an expression-injection pattern that GitHub's security hardening guide warns against. The value here is always a 40-hex-char SHA so there's no real risk, but the safer idiom passes it through an env var:
| --benchmark-save=base \ | |
| - name: Check out base | |
| env: | |
| BASE_SHA: ${{ steps.refs.outputs.base }} | |
| run: git checkout --force --detach "$BASE_SHA" | |
| working-directory: . |
| - name: Check out head | ||
| run: git checkout --force --detach ${{ steps.refs.outputs.head }} | ||
| working-directory: . | ||
|
|
There was a problem hiding this comment.
Same expression-injection pattern as the Check out base step — same fix applies:
| - name: Check out head | |
| env: | |
| HEAD_SHA: ${{ steps.refs.outputs.head }} | |
| run: git checkout --force --detach "$HEAD_SHA" | |
| working-directory: . |
Two patterns: latency measures a single round-trip repeated by pytest-benchmark for a per-request distribution; throughput drives a bounded in-flight window so it does not starve under its own backlog.
Interpolating step outputs into run scripts is the injection-prone pattern GitHub's hardening guide warns about; harmless for SHAs, but the env-var idiom costs nothing.
|
Review comments addressed, PTAL @claude |
|
Claude finished @caspervonb's task in 58s —— View job Review
Both inline suggestions have been applied correctly:
env:
BASE_SHA: ${{ steps.refs.outputs.base }}
run: git checkout --force --detach "$BASE_SHA"
env:
HEAD_SHA: ${{ steps.refs.outputs.head }}
run: git checkout --force --detach "$HEAD_SHA"Both match the suggested idiom exactly. ✅
No issues remaining. LGTM. 🟢 |
Adds a
benchworkflow that runs the nats-core benches on a PR's base commit and its head on the same runner, then compares head against the same-runner baseline and fails past a regression threshold. Same-machine comparison is the only way these microbenchmark numbers mean anything.Also fixes
bench_protocol.py, which passedstrtoencode_pub/encode_hpubafter those moved tobytessubjects/replies — without it the workflow would have nothing green to run.