Skip to content

benchmarks: support a hand-run, single-machine results model, and report a noise band #562

Done

Description

@seabbs-bot

Current behaviour

With benchmarks = true the kit writes two managed workflows, both always and together (src/scaffold.jl, lines 146 to 158): benchmark.yaml and benchmark-history.yaml.
There is no option to write one without the other, or to make the pull request comparison optional.

benchmark.yaml runs on every pull request that touches src, ext, benchmark or the AD fixtures.
It benchmarks the base and the pull request in two separate jobs on two separate ubuntu-latest runners (templates/.github/workflows/benchmark.yaml, lines 48 to 60).
The comment on lines 8 to 13 gives the reason: separate jobs let the AD benchmarks compare across an API change, and keep one runner from loading two heavy AD stacks.
Each benchmark is run once per revision with seconds = 1 (line 110).

compare_comment (src/benchmarks.jl) then reports every ratio against a fixed 5% threshold (CHANGE_THRESHOLD = 0.05, line 365) with red and green markers and a bucket table.
Nothing in the harness controls or measures noise:

  • the two revisions never share a runner, so machine differences between the two jobs count as change;
  • the runs are not interleaved or repeated;
  • no A/A comparison (the same revision twice) is run, so the comment cannot say how large a ratio can be by chance;
  • the comment never fails or gates anything, so a reader has to judge each ratio by eye.

benchmark-history.yaml runs on pushes to main and on tags, on one ubuntu-latest job, and deploys plots and tables to a benchmarks branch under history/.
Each deploy replaces that folder (docs/src/getting-started/benchmarking.md, line 89).
The kit's harness (src/benchmarks.jl) records no description of the machine in the results it writes.

Why this is a problem

On shared runners the noise between two jobs is larger than the 5% threshold the comment colours by.
On ComposableRecurrences.jl, on a pull request that changed no timed code, the comment reported ratios from 0.25x to 1.54x.
On another push it reported a uniform 1.35x to 1.8x slowdown in one group, which disappeared on the next run and did not appear in a local alternating A/B of the same two revisions.
Both were on EpiAware/ComposableRecurrences.jl#907, whose benchmark comment is edited in place on each push.

A comment that shows large red and green ratios for unchanged code teaches reviewers to ignore it.
It also costs a long run on every pull request: ComposableRecurrences.jl's suite takes close to the 90 minute job limit (#533 item 3).
Raising or tuning the threshold does not fix this, because the size of the noise is not measured.

Proposed change

Support a second benchmark model next to the current one, and make the pull request comparison optional.
The model below is the one the Wren.jl package (JuliaBayes) uses; this draft describes what is in its bench/ directory.

The Wren.jl model

  • A benchmark suite (bench/suite/run.jl) is run by hand on one named machine.
    It writes one JSON file per run, named <UTC timestamp>-<short sha>.json.
    The file records the git sha, the commit date, a label, whether the tree was dirty, the Julia version, the CPU model, thread count, memory and OS, the Julia and BLAS thread counts, and the version of every package in the manifest.
  • Saving is guarded.
    The script refuses to save from a dirty tree, since the sha would not describe the code, and refuses to save unless Julia runs with the fixed thread count the runs are compared at.
    It sets BLAS to one thread to keep results consistent.
    --no-save prints the table without saving.
    --release labels the run with the release tag and checks that the commit carries it.
  • Runs are committed to a benchmark-results branch (bench/suite/results_branch.jl).
    The script adds the file through a temporary worktree, rewrites runs/index.json and pushes.
    A second script, remove.jl, removes a noisy run by file or sha, after listing it and asking for confirmation.
  • The suite is not run on CI.
    The README says timings there are too inconsistent, and that the runs are made by hand on a maintainer's machine for each commit to main and each release.
  • A small website (bench/web, Svelte and Vite) shows one run as a table, compares two runs (tip against base, cells coloured by ratio, with changes under 5% treated as noise and only faintly coloured up to 10%), and has a history tab with one chart per model.
    A workflow (.github/workflows/bench-site.yml) builds it from the results branch and publishes it to a bench/ folder on gh-pages.
    It runs when the results branch is pushed to, when bench/web changes, and by hand.
  • One-off comparisons live in bench/adhoc/, which has its own Project.toml and README, so they do not enter the tracked history.
    One script there times a reference implementation twice and reports the second as "(repeat)", so the ratio shows drift between two measurements of the same code.
    That is a manual A/A check; Wren.jl does not compute a noise band automatically.
  • Timings use the minimum over samples, which the Wren.jl docs give as the estimator that varies least.

What the kit could add

  1. Noise band first.
    Report an A/A band wherever the kit reports ratios.
    Add a mode to the managed benchmark/run.jl that runs the suite twice at one revision and saves both, and teach compare_comment to print, per group, the spread of the A/A ratios (for example the median and the 90th percentile of |log ratio|).
    Mark a change only when it lies outside that band, and say in the comment that it is within noise when it does not.
    In benchmark.yaml this is one more job (base against base on a second runner), so the comment can show the band measured on the same infrastructure as the comparison.
  2. Optional per-pull-request comparison.
    A scaffold option, for example benchmark_pr = :always | :label | :off, defaulting to :always so nothing changes on sync.
    :label runs the job only when a benchmark label is on the pull request, the way downstream.yaml is already triggered by a label (templates/.github/workflows/downstream.yaml, lines 14 to 28).
    :off omits the workflow.
    The comment is advisory under every setting.
  3. Same-runner, interleaved runs as an option.
    For packages where the separate-job design is not needed, run base and pull request in one job, alternating revisions for several rounds, and take the minimum of each.
    This removes machine-to-machine noise at the cost of the fixture isolation the current comment describes, so it should be opt-in.
  4. A hand-run recording path.
    A managed benchmark/record.jl that implements the guarded save described above, writing to a results folder on the existing benchmarks branch (for example runs/, outside history/, which the history deploy owns).
    The machine description goes into the file.
    It needs the same concurrency group as the history deploy (benchmark-history-deploy, documented in benchmarking.md) if a workflow ever writes there too.
  5. Compare and history pages in the docs.
    Extend build_benchmark_page (src/docs_build.jl, line 1544) to read runs/index.json, list runs with machine and label, render a compare table for a chosen pair, and a history table across runs on one machine.
    Pages could be Documenter-rendered at build time, avoiding a JavaScript application.
    Runs from different machines are shown separately and not compared.
  6. An ad hoc directory.
    Scaffold benchmark/adhoc/ with its own Project.toml and a README, documented as untracked one-off comparisons, so they have a place that does not feed the history.

Items 1 and 2 solve the problem described above and are independent of the rest.

Evidence


Generated by Claude Code

Activity

  1. seabbs-bot commented on Dec 1, 2026

    @seabbs-bot
    CollaboratorAuthor

    A working version of items 1, 3 and 4 now exists in EpiAware/ComposableRecurrences.jl#926, so here is a concrete replacement for the per-PR job.

    What was built there

    • benchmark/ab.jl: one job on one machine.
      Each round runs base, candidate and base again, each a fresh process, in an order that rotates by round.
      The two base runs give the A/A ratio of every benchmark.
    • benchmark/verdict.jl: about 150 lines with no dependencies.
      A benchmark's band is the larger of the 90th percentile of |log A/A ratio| over its group and its own largest A/A ratio.
      A benchmark is called faster or slower only when its minimum and its median are both outside their bands and every round agrees in sign.
    • benchmark/suite/run.jl: the hand-run recording path of item 4, with the machine in the file head, runs/<machine>/ on a benchmark-results branch, and a static history.html (item 5 without a site build).

    What it measured

    Redesign (f1d5fd6) against the earlier main (7b6a4ee), 7 cases, 6 targets, 3 rounds, on a 4-core cloud VM with nothing else running:

    • Run time: about 4 hours 20 minutes for 54 processes, most of it compilation.
    • A/A ratio of the minimum time between two fresh processes of the same commit: median 3% to 8% by target, 90th percentile 18% to 26%, largest 1.5x to 1.8x.
      So a single base-against-PR pair can show 1.5x on unchanged code, on one machine, which is what the current comment reports.
    • Verdicts: 126 cells, 125 within noise, 1 slower (plain Enzyme reverse of one case, 1.39x against a 21% band).
    • Enzyme forward segfaulted in the Julia runtime in 6 of the 7 processes that ran to an end, each time while timing a hand-written baseline; the rows written before a crash are kept and a crashed process is reported as failed.

    The band is conservative: it is the tail of one A/A ratio, and a verdict is taken on the median of the rounds.
    With three rounds this run cannot see a change under about 20%.

    Proposed replacement for benchmark.yaml

    One job in place of the pr and main matrix and the compare job:

    jobs:
      benchmark:
        runs-on: ubuntu-latest
        timeout-minutes: 120
        steps:
          - uses: actions/checkout@v7
            with:
              fetch-depth: 0
          - uses: julia-actions/setup-julia@v3
            with:
              version: '1'
          - uses: julia-actions/cache@v3
          - name: Interleaved comparison with an A/A band
            run: |
              julia benchmark/ab.jl \
                --base=${{ github.event.pull_request.base.sha }} \
                --cand=${{ github.event.pull_request.head.sha }} \
                --rounds=3 --out=ab-results
          - uses: actions/upload-artifact@v7
            with:
              name: ab-results
              path: |
                ab-results/REPORT.md
                ab-results/ab.tsv
                ab-results/round-*
          # Post ab-results/REPORT.md under the existing comment marker.

    What the kit would need

    1. A managed benchmark/ab.jl that alternates processes of the managed benchmark/run.jl over worktrees of the two commits, with the package's benchmark folder copied onto both so they run the same suite.
      The ComposableRecurrences script drives its own matrix.jl; the kit's would drive run_suite.
    2. compare_comment(rounds_dir) taking the rounds, with the band and verdict rule above in place of CHANGE_THRESHOLD.
      The rule is pure functions on (name, min, median) rows, so it can move into Benchmarks as it is.
    3. benchmark_pr = :always | :label | :off as in item 2: a round costs two base runs and one candidate run, so a package with a long suite will want :label.
      The grid measured above does not fit a job.
      Primal with the two reverse modes took about 42 minutes a round here, so a 120 minute job holds two rounds of that, or three of a shorter case list.
    4. The comment stays advisory.

    A shared runner is still noisier than a quiet machine, but the band is measured on that runner in that hour, so the comment says "within noise" where it now says 1.3× to 3.6×.


    Generated by Claude Code

  2. seabbs commented on Dec 3, 2026

    @seabbs
    Member

    No to all this.

    Same-runner, interleaved runs as an option.
    For packages where the separate-job design is not needed, run base and pull request in one job, alternating revisions for several rounds, and take the minimum of each.
    This removes machine-to-machine noise at the cost of the fixture isolation the current comment describes, so it should be opt-in.

    yes to this if not already doing it this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions