Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/scripts/id-bench-compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
# id-bench-compare.sh — diff pkgs/id benchmark medians against the
# committed F11.8 baselines and print a Markdown regression report
# (slice 3 of #539, issue #1513).
#
# Usage: id-bench-compare.sh <bench-output-file> [baseline-file]
#
# Both inputs use the harness's own line format (world_bench.rs):
# bench <name> unit=<unit> median=<value> min=<value> reps=<n>
# baseline.txt is literally a captured harness run plus comments, so
# one parser serves both sides.
#
# A benchmark is flagged when its current median is more than
# BENCH_REGRESSION_THRESHOLD_PCT percent (default 20) above baseline.
# The report goes to stdout; the caller appends it to the GitHub job
# summary. This script ALWAYS exits 0 — slice 3 is non-blocking by
# design: the report informs, it never gates a PR.
set -euo pipefail

threshold="${BENCH_REGRESSION_THRESHOLD_PCT:-20}"

if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "usage: id-bench-compare.sh <bench-output-file> [baseline-file]" >&2
exit 2
fi

current_file="$1"
baseline_file="${2:-pkgs/id/benches/baseline.txt}"

if [ ! -f "$current_file" ]; then
echo "## Benchmark regression report"
echo
echo "⚠️ Benchmark output file \`$current_file\` not found — the bench run produced no results to compare."
exit 0
fi

if [ ! -f "$baseline_file" ]; then
echo "## Benchmark regression report"
echo
echo "⚠️ Baseline file \`$baseline_file\` not found — nothing to compare against."
exit 0
fi

awk -v threshold="$threshold" '
function parse(file, median, unit, order, line, i, f, kv) {
while ((getline line < file) > 0) {
if (line !~ /^bench /) continue
split(line, f, /[ \t]+/)
name = f[2]
for (i = 3; i in f; i++) {
split(f[i], kv, "=")
if (kv[1] == "median") median[name] = kv[2] + 0
if (kv[1] == "unit") unit[name] = kv[2]
}
if (!(name in seen)) { seen[name] = 1; order[++n] = name }
}
close(file)
}
BEGIN {
n = 0
parse(ARGV[1], base_median, base_unit, base_order)
base_n = n
n = 0
parse(ARGV[2], cur_median, cur_unit, cur_order)

print "## Benchmark regression report (vs committed baselines)"
print ""
printf "Threshold: a benchmark is flagged when its median is more than %s%% above baseline. Baselines were taken on the reference machine in `pkgs/id/benches/BASELINES.md`; shared CI runners differ, so treat flags as a prompt to investigate, not a verdict.\n", threshold
print ""
print "| benchmark | unit | baseline median | current median | change | status |"
print "| --- | --- | ---: | ---: | ---: | --- |"
regressions = 0
for (i = 1; i <= base_n; i++) {
name = base_order[i]
if (name in cur_median) {
pct = (cur_median[name] - base_median[name]) / base_median[name] * 100
if (pct > threshold) {
status = "⚠️ regression"
regressions++
reg_list[++reg_n] = sprintf("%s (+%.1f%%)", name, pct)
} else {
status = "ok"
}
printf "| %s | %s | %.3f | %.3f | %+.1f%% | %s |\n", name, base_unit[name], base_median[name], cur_median[name], pct, status
} else {
printf "| %s | %s | %.3f | — | — | not run |\n", name, base_unit[name], base_median[name]
}
}
for (i = 1; i <= n; i++) {
name = cur_order[i]
if (!(name in base_median)) {
printf "| %s | %s | — | %.3f | — | no baseline |\n", name, cur_unit[name], cur_median[name]
}
}
print ""
if (regressions > 0) {
printf "⚠️ **%d benchmark(s) regressed more than %s%%:** ", regressions, threshold
for (i = 1; i <= reg_n; i++) printf "%s%s", reg_list[i], (i < reg_n ? ", " : "")
print ""
} else {
printf "✅ No benchmark regressed more than %s%% against the committed baselines.\n", threshold
}
}
' "$baseline_file" "$current_file"
90 changes: 90 additions & 0 deletions .github/workflows/id-bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Benchmark regression reporting for pkgs/id — F11.8 slice 3 (#1513).
#
# Runs the four slice-1 benchmarks (world_bench) and diffs their medians
# against the committed slice-2 baselines in pkgs/id/benches/baseline.txt,
# using .github/scripts/id-bench-compare.sh. The report lands in the job
# summary and as a run artifact.
#
# NON-BLOCKING BY DESIGN: this workflow is separate from the required
# "nix flake check" gate in id-check.yml, the bench step is
# continue-on-error, and the compare script always exits 0. A regression
# flag informs the PR — it never fails a required check. Baselines were
# taken on the fleet laptop (see pkgs/id/benches/BASELINES.md); shared
# CI runners are a different machine class, so flags are a prompt to
# investigate, not a verdict.

name: id bench

on:
push:
branches: [main]
paths:
- "pkgs/id/**"
- ".github/workflows/id-bench.yml"
- ".github/scripts/id-bench-compare.sh"
pull_request:
paths:
- "pkgs/id/**"
- ".github/workflows/id-bench.yml"
- ".github/scripts/id-bench-compare.sh"
workflow_dispatch:

permissions:
contents: read

# Same concurrency shape as id-check.yml: push-to-main runs are keyed by
# run_id so every merged tree gets its own completed run; PR runs share
# a per-ref group so a new push supersedes the stale run.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_id || github.ref }}
cancel-in-progress: true

jobs:
bench:
name: benchmark regression report
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v7

- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
with:
extra-conf: |
accept-flake-config = true

# Same store cache as the PR gate, so the bench build starts warm
# (#288).
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15

# Full-size workloads, exactly as the baselines were taken
# (BASELINES.md): --quick numbers are smoke sizes and are never
# comparable to the committed baselines.
- name: Run benchmarks
id: bench
continue-on-error: true
working-directory: pkgs/id
run: |
nix develop --command just bench 2>&1 | tee "$GITHUB_WORKSPACE/bench-output.txt"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the benchmark command's exit status

If Nix setup, compilation, or the benchmark harness fails, this pipeline still succeeds whenever tee succeeds. The workflow leaves the shell unspecified, which GitHub documents as bash -e {0}, without pipefail. Consequently, steps.bench.outcome remains success, bypassing the failure-report branch in the comparison step and potentially reporting “No benchmark regressed” from empty or incomplete results. Specify shell: bash or enable pipefail so failures reach the existing warning branch; continue-on-error already preserves the intended non-blocking behavior.

Useful? React with 👍 / 👎.


- name: Compare against committed baselines
if: always()
run: |
if [ "${{ steps.bench.outcome }}" != "success" ]; then
{
echo "## Benchmark regression report"
echo
echo "⚠️ The benchmark run did not complete (step outcome: ${{ steps.bench.outcome }}), so there are no results to compare. This report is non-blocking; see the run log."
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
.github/scripts/id-bench-compare.sh bench-output.txt pkgs/id/benches/baseline.txt | tee bench-report.md >> "$GITHUB_STEP_SUMMARY"

- name: Upload benchmark output
if: always()
uses: actions/upload-artifact@v7
with:
name: bench-output
path: |
bench-output.txt
bench-report.md
if-no-files-found: ignore
18 changes: 18 additions & 0 deletions pkgs/id/benches/BASELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,21 @@ per-participant chat rate limit (50 messages per 10 s window,
across four senders (25 rounds each), which stays under the burst
cap while measuring the same delivery path. No production code
changed.

## CI regression reporting (slice 3, #1513)

The `id bench` workflow (`.github/workflows/id-bench.yml`) runs the
four benchmarks at full size on PRs touching `pkgs/id/**` and on
pushes to main, then diffs the medians against `baseline.txt` with
`.github/scripts/id-bench-compare.sh`. Any benchmark more than 20%
slower than baseline is named, with its percentage, in the job
summary and the uploaded `bench-output` artifact.

The reporting is deliberately non-blocking: it is a separate workflow
from the required `nix flake check` gate, and the compare script
always exits 0. The threshold is adjustable via the
`BENCH_REGRESSION_THRESHOLD_PCT` environment variable in the compare
step. Remember the caveat above: baselines were taken on the laptop
above, CI runners are a different machine class — a flag is a prompt
to investigate (ideally by re-running on the reference machine), not
proof of a regression.
Loading