Skip to content

chore: gungraun benchmarks#390

Merged
ebfull merged 3 commits intotachyon-zcash:mainfrom
turbocrime:iai-bench-ci
Jan 30, 2026
Merged

chore: gungraun benchmarks#390
ebfull merged 3 commits intotachyon-zcash:mainfrom
turbocrime:iai-bench-ci

Conversation

@turbocrime
Copy link
Copy Markdown
Collaborator

@turbocrime turbocrime commented Jan 26, 2026

Summary

Add gungraun (iai-callgrind) benchmarks for deterministic, instruction-count-based performance tracking. This enables reliable CI regression detection by measuring CPU instructions instead of wall-clock time.

Closes #47. Supersedes #375.

Why gungraun/iai-callgrind?

  • Deterministic: Measures CPU instructions, not wall-clock time — no statistical variance
  • CI-friendly: Single run produces reliable results (no need for many samples)
  • Fine-grained: Small functions can be meaningfully benchmarked
  • Cross-platform: Docker support allows macOS developers to run benchmarks locally

Changes

CI Workflow (.github/workflows/bench.yml)

  • Runs benchmarks on every PR and push to main
  • Path filtering skips benchmarks when no Rust files changed
  • Baseline caching per-branch for regression comparison
  • Uses github-action-benchmark for PR comments and summary reports

Note: External PRs cannot receive benchmark comments due to GitHub token permissions.

Local Development

  • just bench — auto-detects platform (native Linux, Docker on macOS)
  • Graceful Docker shutdown with proper signal forwarding (no orphan containers)

Feature Flag

Uses unstable-test-fixtures feature to expose test utilities needed by benchmarks. This follows the project convention for features with potentially unstable API surface.

Metrics

Transforms gungraun JSON output via .github/scripts/transform-gungraun.jq. Reports 6 key metrics:

  • Instructions (Ir)
  • L1 hits, LL hits, RAM hits
  • Total read+write accesses
  • Estimated cycles

Benchmark Coverage

Crate Benchmarks
ragu_pcd application_build, seed, fuse, verify_leaf, verify_node, rerandomize
ragu_primitives element ops (mul, invert, fold_8, is_zero, multiadd_8), point ops (double, add_incomplete, double_and_add_incomplete, endo), boolean (multipack_256), sponge (absorb_squeeze), endoscalar ops
ragu_circuits polynomial commits (structured, unstructured), polynomial ops (revdot, fold, eval, dilate), synthesis (into_object, rx, ky, square), registry ops
ragu_arithmetic MSM (64–4096 elements), FFT (k=10,14,18), ell (k=10,14), polynomial (with_roots, eval, factor), field (dot, geosum)

Review Feedback Addressed

Feedback Resolution
Graceful Docker shutdown Added signal trapping, --init flag
StepRng deprecated Switched to StdRng::seed_from_u64()
Simplify workflow Removed baseline generation fallback and apt caching
Feature naming Renamed to unstable-test-fixtures

Future Work

Test Plan

  • CI workflow runs successfully
  • just bench works on Linux (native) and macOS (via Docker)
  • just bench -- --save-summary=json generates summary files
  • Benchmark comment appears on internal PRs needs to merge first

@turbocrime turbocrime requested a review from ebfull as a code owner January 26, 2026 21:50
@turbocrime turbocrime force-pushed the iai-bench-ci branch 3 times, most recently from 3f9ddbb to c342f0d Compare January 27, 2026 02:23
@turbocrime
Copy link
Copy Markdown
Collaborator Author

unfortunately, it's confirmed that external PRs can't activate the 'comment' feature because the github token provided to external PRs does not have the necessary permissions.

Copy link
Copy Markdown
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

Great work! 👏 very solid starting point for us.

Left some suggestions (open to chat), I will likely push one commit improving on justfile (open to revert if you dislike)

Comment thread Cargo.toml
Comment thread justfile Outdated
Comment thread crates/ragu_arithmetic/benches/arithmetic.rs Outdated
Comment thread crates/ragu_arithmetic/benches/arithmetic.rs Outdated
Comment thread crates/ragu_primitives/benches/primitives.rs Outdated
Comment thread crates/ragu_circuits/src/lib.rs
Comment thread crates/ragu_circuits/benches/circuits.rs Outdated
@turbocrime turbocrime force-pushed the iai-bench-ci branch 2 times, most recently from b3cd23c to c2a3636 Compare January 27, 2026 11:32
Copy link
Copy Markdown
Collaborator

@TalDerei TalDerei left a comment

Choose a reason for hiding this comment

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

first pass observations

Comment thread crates/ragu_pcd/src/lib.rs Outdated
Comment on lines +20 to +22
#[cfg(any(test, feature = "gg-callgrind"))]
#[doc(hidden)]
pub mod test_fixtures;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unstable-test-fixtures #375 (review)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we should call it unstable-test-fixtures (sorry for the verbosity!) because I want us to get in the habit of labeling features that might have breaking API changes.

#375 (review)

i guess i don't understand here - what's 'unstable' about this? no production API surface should actually change. i just didn't want to default expose things that weren't for consumers (nobody wants to use MySimpleCircuit or see it in their autocomplete)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

changed feature name to unstable-test-fixtures

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#375 (comment) wasn't addressed; deferring to @ebfull on benchmarking granularity in this first pass.

Comment thread .github/workflows/bench.yml Outdated
- name: Missing baseline. Run baseline benchmarks
id: baseline-bench
if: github.event_name == 'pull_request' && !steps.check-baseline.outputs.exists
continue-on-error: true
Copy link
Copy Markdown
Collaborator

@TalDerei TalDerei Jan 27, 2026

Choose a reason for hiding this comment

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

continue-on-error: true can slip into silent benchmark failures?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is necessary because it's possible that there will be no benchmark results or broken benchmarks in the base. continue-on-error is present so it may proceed with measuring the present branch and compare it to nothing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed fallback baseline generation

Comment thread .github/workflows/bench.yml Outdated
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt
Copy link
Copy Markdown
Collaborator

@TalDerei TalDerei Jan 27, 2026

Choose a reason for hiding this comment

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

I’d be in favor of starting with a simpler script that just works, with minimal surface area, and then iteratively layering in this kind of caching complexity.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed apt cache behavior

@turbocrime turbocrime force-pushed the iai-bench-ci branch 3 times, most recently from 1f62d07 to 11ec59d Compare January 28, 2026 00:35
@turbocrime turbocrime requested a review from alxiong January 28, 2026 01:06
@ebfull ebfull self-assigned this Jan 28, 2026
@TalDerei TalDerei added the sean-unread Queued for Sean's review label Jan 28, 2026
Copy link
Copy Markdown
Collaborator

@ebfull ebfull left a comment

Choose a reason for hiding this comment

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

Main concern is that ragu_pasta should not be a dependency of any of the crates in this workspace. (dev-dependency only)

Comment thread .github/workflows/rust.yml Outdated
components: clippy
- name: Run clippy
run: cargo clippy --workspace --lib --tests --benches --locked -- -D warnings
run: cargo clippy --workspace --lib --tests --benches --locked --features unstable-test-fixtures -- -D warnings
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if we want to --all-features this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

switched to --all-features

gadgets::{GadgetKind, Kind},
maybe::Maybe,
};
use ragu_pasta::Fp;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can avoid ragu_circuits depending on ragu_pasta (strict requirement!) by making the fixtures below be generic over the field type.

Copy link
Copy Markdown
Collaborator Author

@turbocrime turbocrime Jan 29, 2026

Choose a reason for hiding this comment

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

now parameterized.

dependency moved to dev dependency.

created issue suggesting cargo-deny to enforce this strict requirement #402

pub times: usize,
}

impl Circuit<Fp> for SquareCircuit {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
impl Circuit<Fp> for SquareCircuit {
impl<F: Field> Circuit<F> for SquareCircuit {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

now parameterized

Comment thread crates/ragu_circuits/Cargo.toml Outdated
ff = { workspace = true }
group = { workspace = true }
ragu_core = { path = "../ragu_core", version = "0.0.0" }
ragu_pasta = { path = "../ragu_pasta", version = "0.0.0", features = ["baked"] }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This breaks a dependency requirement of mine; we definitely don't want ragu_circuits to depend on ragu_pasta because then Ragu is not agnostic to the curve cycle.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

dependency moved to dev dependency.

created issue suggesting cargo-deny to enforce this strict requirement #402

Comment thread crates/ragu_pcd/src/tests.rs Outdated
Comment on lines +20 to +22
// ============================================================================
// Test fixtures for registration_errors tests
// ============================================================================
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

non-blocking nit: I have a general principle, which is that whenever I see "sectioned" comments in code like this I tend to think it means the file is too large and should be broken up into separate files/modules.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

the original main version already had these (local) fixtures and the tests collected in a single file, the section header is really just diff noise.

some of this is now reverted - tests are back in their original location as integration tests rather than unit tests (this also helped address the dependency issue). the set of fixtures is now minimized and lives in a dedicated module.

Comment thread Cargo.lock
Comment thread Cargo.lock Outdated

[[package]]
name = "serde_json"
version = "1.0.148"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

any reason we can't use serde_json 1.0.149?

Copy link
Copy Markdown
Collaborator Author

@turbocrime turbocrime Jan 29, 2026

Choose a reason for hiding this comment

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

now serde_json 1.0.149

Comment thread Cargo.lock Outdated
[[package]]
name = "zerocopy"
version = "0.8.25"
version = "0.8.31"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

any reason we can't use zerocopy 0.8.33?

Copy link
Copy Markdown
Collaborator Author

@turbocrime turbocrime Jan 29, 2026

Choose a reason for hiding this comment

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

now zerocopy 0.8.33

Comment thread Cargo.lock Outdated

[[package]]
name = "zmij"
version = "1.0.9"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

any reason we can't use zmij 1.0.14?

Copy link
Copy Markdown
Collaborator Author

@turbocrime turbocrime Jan 29, 2026

Choose a reason for hiding this comment

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

now zmij 1.0.14

@ebfull ebfull removed the sean-unread Queued for Sean's review label Jan 29, 2026
Copy link
Copy Markdown
Collaborator

@ebfull ebfull left a comment

Choose a reason for hiding this comment

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

Excellent, glad we're going to start having these in the codebase.

@ebfull ebfull merged commit 16c2af9 into tachyon-zcash:main Jan 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Criterion benchmark suite

4 participants