Skip to content

feat(bench): add baseline benchmark capture and CI regression check - #301

Open
aaniya22 wants to merge 2 commits into
mohu-org:mainfrom
aaniya22:feat/bench-baseline-ci-gate
Open

feat(bench): add baseline benchmark capture and CI regression check#301
aaniya22 wants to merge 2 commits into
mohu-org:mainfrom
aaniya22:feat/bench-baseline-ci-gate

Conversation

@aaniya22

@aaniya22 aaniya22 commented Jul 15, 2026

Copy link
Copy Markdown

What

Adds baseline benchmark capture and a non-blocking CI regression-check job for the benches/ directory. Closes #287.

Why

The benches/ directory existed with no documented baseline result, no CI gate to catch performance regressions, and no comparison-target documentation — so a PR could introduce a 10x regression in a core op with no signal, and no one evaluating the project could see how fast it actually is.

How

  • Scope note: mohu-array (the public NdArray<T> type referenced in the issue's own example) isn't implemented yet — array.rs is currently empty. Rather than block on that, this benchmarks mohu-buffer, the allocation/layout layer NdArray will sit on top of, which is fully implemented today. Once NdArray lands, these benchmarks should be extended to array-level operations.
  • Wired a Criterion [[bench]] target into mohu-buffer pointing at benches/ndarray_ops.rs. Benchmarks Buffer::zeros and Buffer::alloc at 100 / 10,000 / 1,000,000 elements (f64).
  • Captured a baseline and committed it as portable JSON via critcmp --export (benches/baselines/main.json) — avoids depending on Criterion's internal target/criterion directory format in CI.
  • Added benches/README.md: how to run locally, how to compare against the committed baseline, the current baseline table (with a hardware caveat, since this was captured on a shared Codespaces vCPU, not a dedicated benchmark machine), and the intended NumPy-equivalent comparison targets (documented by name for future reference; not executed in CI).
  • Added a non-blocking bench-compare CI job (PR-only) that runs benchmarks and posts a critcmp comparison against the committed baseline to the job summary, for human review — mirrors the existing non-blocking pattern used by coverage and miri in this workflow. Kept it informational rather than a hard gate since the issue asks for flagging regressions "for human review," not a hard fail.
  • Not in scope: LLVM optimization flag / target-CPU pinning documentation (also flagged as missing in the issue) — happy to follow up separately if maintainers want that split out.

Checklist

  • cargo test --workspace passes
  • cargo clippy --workspace -- -D warnings passes
  • cargo fmt --all applied
  • CHANGELOG.md updated (if user-facing change) — not user-facing, internal tooling only
  • Benchmarks added or updated (if performance-sensitive path)

Summary by CodeRabbit

  • New Features

    • Added Criterion-based benchmarks for buffer allocation and zero-initialization across multiple sizes.
    • Added a pull request benchmark check that compares results to the committed main baseline, highlights deltas in the run summary, and allows small (~±5%) noise on shared CI runners.
  • Documentation

    • Added a Criterion benchmark README with local run/save/compare instructions, benchmark coverage notes, and guidance for interpreting the baseline.

…ohu-org#287)

- Wire mohu-buffer with a Criterion bench target (benches/ndarray_ops.rs),
  benchmarking Buffer::zeros and Buffer::alloc at 3 sizes. mohu-array's
  NdArray type is not yet implemented, so this exercises the allocation
  layer it will be built on.
- Capture and commit a baseline (benches/baselines/main.json) via critcmp.
- Document how to run/compare benchmarks and the intended NumPy comparison
  targets in benches/README.md.
- Add a non-blocking CI job (bench-compare) that runs benchmarks on PRs and
  posts a comparison against the committed baseline to the job summary.

Signed-off-by: Aaniya <aaniyaatomar@gmail.com>
@github-actions

Copy link
Copy Markdown

PR Check Summary

Item Value
Branch feat/bench-baseline-ci-gate
Changed crates crates/mohu-buffer
Files changed 7

CI will run: build, test, clippy, fmt, cargo-deny, DCO, semver.
Reviewer assigned from CODEOWNERS.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 066a96ae-d626-4062-af69-9a16db39bb19

📥 Commits

Reviewing files that changed from the base of the PR and between 12472dd and 8cb1073.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

📝 Walkthrough

Walkthrough

Adds Criterion benchmarks for mohu-buffer, commits a benchmark baseline, documents benchmark usage and targets, and introduces a non-blocking pull-request CI job that compares benchmark results against the baseline.

Changes

Benchmark pipeline

Layer / File(s) Summary
Benchmark definition and wiring
Cargo.toml, crates/mohu-buffer/Cargo.toml, benches/ndarray_ops.rs
Configures Criterion and registers benchmarks for Buffer::zeros and Buffer::alloc across multiple F64 sizes.
Baseline artifact and benchmark documentation
benches/baselines/main.json, benches/README.md
Adds recorded Criterion results and documents local runs, baseline comparisons, current measurements, future targets, and the regression policy.
Pull-request comparison job
.github/workflows/ci.yml
Runs benchmark comparison on pull requests, compares results with the committed baseline, and writes output to the GitHub step summary without blocking CI.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BenchCompareJob
  participant CargoBench
  participant Critcmp
  participant MainBaseline
  participant StepSummary
  BenchCompareJob->>CargoBench: run ndarray_ops and save PR baseline
  CargoBench-->>BenchCompareJob: benchmark results
  BenchCompareJob->>Critcmp: compare PR results with main baseline
  Critcmp->>MainBaseline: read main.json
  Critcmp-->>BenchCompareJob: comparison output and deltas
  BenchCompareJob->>StepSummary: write comparison and noise note
Loading

Possibly related PRs

  • mohu-org/mohu#113: Updates CI job orchestration and gating behavior related to the benchmark comparison job.

Suggested reviewers: bbn08, mugiwaraluffy56

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning It adds the baseline, local docs, and CI comparison job, but #287's reproducibility guidance for LLVM/CPU bench settings remains unimplemented. Document the benchmark toolchain, LLVM optimization flags, and target CPU baseline, or move those requirements to a follow-up issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the added benchmark baseline capture and CI regression check.
Out of Scope Changes check ✅ Passed All changes stay within benchmarking, documentation, and CI infrastructure for the benches/ workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/mohu-buffer/Cargo.toml (1)

38-38: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant dev-dependency.

mohu-dtype is already declared as a regular dependency in this crate (line 19), so it is automatically available to tests and benchmarks. You don't need to declare it again under [dev-dependencies].

♻️ Proposed refactor
 [dev-dependencies]
 criterion.workspace  = true
-mohu-dtype.workspace = true
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/mohu-buffer/Cargo.toml` at line 38, Remove the redundant mohu-dtype
entry from the [dev-dependencies] section of Cargo.toml, keeping its existing
regular dependency declaration unchanged so tests and benchmarks continue using
it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 140-147: Correct the YAML structure for the bench-compare job by
aligning bench-compare with the other top-level jobs under jobs, then indenting
name, runs-on, needs, if, continue-on-error, and steps as its properties. Ensure
it is no longer nested within bench-check and the workflow parses without
duplicate keys.

---

Nitpick comments:
In `@crates/mohu-buffer/Cargo.toml`:
- Line 38: Remove the redundant mohu-dtype entry from the [dev-dependencies]
section of Cargo.toml, keeping its existing regular dependency declaration
unchanged so tests and benchmarks continue using it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 88078c08-f241-48f9-951f-6d64da54373f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c07775 and 12472dd.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • Cargo.toml
  • benches/README.md
  • benches/baselines/main.json
  • benches/ndarray_ops.rs
  • crates/mohu-buffer/Cargo.toml

Comment thread .github/workflows/ci.yml Outdated
bench-compare's comment and job block were inconsistently indented
relative to sibling jobs, risking YAML structural ambiguity.
Normalized to match the 2/4/6-space pattern used by other jobs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant