Benchmarking
Benchmarking is off unless you pass benchmarks = true. See Infrastructure and template sync for which files are managed and which the package owns.
Opting in
Pass benchmarks = true to scaffold or update.
scaffold(pkgdir(MyPackage); benchmarks = true)This writes the benchmark CI callers, the benchmark/ suite skeleton and the package-owned benchmark docs prose hook.
The benchmark/ suite
Write your measurements in benchmark/benchmarks.jl as a BenchmarkTools BenchmarkGroup named SUITE. Put AD-gradient benchmarks under an "AD gradients" group, so the pull request comment shows them as a scenario-by-backend matrix.
const SUITE = BenchmarkGroup()
SUITE["Evaluation"]["logpdf"] = @benchmarkable logpdf(d, x)
SUITE["AD gradients"]["logpdf"]["ForwardDiff"] = @benchmarkable gradient(...)Run the suite locally with julia --project=benchmark benchmark/run.jl.
Files in benchmark/
benchmark/benchmarks.jl(package-owned) definesSUITE.benchmark/run.jl(managed) runs this checkout's suite and saves the results to JSON.benchmark/compare.jl(managed) builds the base-versus-head comparison comment.benchmark/Project.toml(package-owned) is the benchmark environment.
Adding scenarios
Extend SUITE in benchmark/benchmarks.jl. Evaluation measurements go under an evaluation group and gradient measurements under "AD gradients". A new scenario is measured on both sides of a pull request once it is on the pull request branch. Describe what the suite covers in docs/benchmarks.md. It is added at the foot of the "Performance over time" page under "About these benchmarks".
Two workflows
The kit ships two benchmark workflows that never run on the same event.
PR comparison
benchmark.yaml runs on pull requests that touch src, ext, benchmark or the AD fixtures. It posts one comparison comment, and a re-run updates that comment.
The comparison is informational by default. To fail the check on a slow pull request, set a regression threshold.
update("."; benchmark_regression_threshold = 1.2)1.2 flags any benchmark at least 20% slower, as a ratio of pull request to base minimum time. Pick a threshold above your suite's run-to-run noise, or noisy benchmarks will fail the check at random. To turn the gate off, delete the BENCHMARK_REGRESSION_THRESHOLD line from benchmark.yaml.
How the comparison works
Each revision is benchmarked in its own job, so the base runs its own sources and fixtures and the pull request runs its own. This lets AD-gradient benchmarks be compared across an API change, and keeps one runner from loading two AD stacks at once. The comment is built by EpiAwarePackageTools.Benchmarks.compare_comment. It has a bucketed summary and collapsed detail tables split into evaluation and AD-gradient sections.
With a threshold set, the comment still posts and ends with a regression gate section naming the slow benchmarks. A final step then fails the job, listing them. The rule is the same as the regression flag on the history page. A bare update keeps the committed threshold.
Performance history
benchmark-history.yaml runs on pushes to main and on tags. It benchmarks the last few tagged releases and the pushed commit with AirspeedVelocity. It deploys a plot and ratio table per benchmark to history/ on a dedicated benchmarks branch. These become the "Performance over time" page in the site's Benchmarks section. The page's trend plot needs Plots in the docs environment, which scaffold adds when benchmarks = true.
The benchmarks branch
The timeline is not on gh-pages because Documenter force-pushes that branch on every docs build. The branch needs no cleanup workflow. Pull request results stay as job artifacts, which GitHub expires, and only pushes to main, tags and manual dispatch write the branch. Each deploy replaces the published folder, so the branch does not grow. Writers share the benchmark-history-deploy concurrency group without cancelling, so a tag push and a main push queue rather than lose commits. Anything else that writes the branch must join that group, except a run of the extra tiers, which uses its own group and writes only history/tiers/.
Raw per-revision results are under history/results/, with latest.json for the revision the run measured. The AD comparison docs page reads its gradient numbers from there.
The Performance over time page
It opens with a summary across the package and a combined trend plot. The summary has one row per suite, with its ratio against the oldest shown revision, a trend arrow and a regression flag. Each suite then has its own section with timing and allocation tables. Without Plots the plot becomes an @info note and the rest of the page still builds.
A scheduled tier for a slow grid
A grid too slow for every push can run once a day instead. Name it as an extra tier.
update("."; benchmark_history_tiers = ["full"])benchmark-history.yaml then times the full tier on a daily schedule, on the newest commit of main only. Pull requests and pushes never run it. To time it by hand, run the workflow from the Actions tab with tier set to full. Read BENCHMARK_TIER in benchmark/benchmarks.jl to add the slow part of the grid. It is empty for the default tier and "full" on the schedule.
To have the AD comparison page read the tier, set const AD_BENCHMARK_TIER = "full" in docs/docs_config.jl.
Where a tier's results go
The default tier writes history/results/ as before. Each extra tier writes history/tiers/<tier>/results/, with latest.json and the file for the revision it timed. Neither run touches the other's files, so the AD comparison page always reads the tier it names. A run of the extra tiers has its own concurrency group, so a long tier does not hold up a push. A run by hand replaces only the folder of the tier it names.
EpiAwarePackageTools.DocsBuild.published_benchmark_results reads one revision's file from the branch, for either tier. load_ad_benchmarks takes scenarios to keep only some scenarios, such as the registry's.
The step that lists the benchmark groups sets BENCHMARK_LIST_ONLY=true. The seeded suite then adds a placeholder for each gradient rather than preparing it. A suite of your own can do the same.
Unregistered [sources] dependencies
Both workflows handle dependencies pinned by git url and revision in [sources] because they are not yet registered. You do not need to configure anything.
How unregistered dependencies are resolved
Both workflows install the package as a dependency, and Pkg honours only the active project's [sources]. An unregistered git pin would fail with has no known versions!, including in the temp projects AirspeedVelocity's benchpkg builds per revision.
A step calls EpiAwarePackageTools.Benchmarks.bootstrap_sources_registry. It clones each unregistered git pin at its revision and registers it in a throwaway LocalRegistry in the runner's depot. Registries are depot-level, so the dependency then resolves by name in every environment on that runner. Nothing is pushed and the registry dies with the runner.
A package with no [sources] skips the step before anything is installed. A package whose [sources] are all path pins or registered names does no registry work. The step stops doing anything as dependencies reach the General registry.
The scratch registry is removed and rebuilt on every run. A cached depot may still hold the previous run's registry, and an unregistered dependency does not bump its version when its revision moves. Reusing it would pin the benchmark to the first registered revision. Once a dependency is registered and the pin dropped, a leftover scratch registry with that name would also fail the depot with a registry hash mismatch.
Limits
A [sources] pin on a package a registry already knows is not honoured. The benchmark resolves it from the registry, and the step warns. Registration is not transitive. If a pinned dependency itself pins an unregistered dependency, repeat that inner pin in the benchmarked package.