Skip to content

feat(#738): add criterion benchmark suite for contract hot paths#838

Merged
Haroldwonder merged 1 commit into
Haroldwonder:mainfrom
theo372001:feature/issue-738-criterion-benches
Jun 29, 2026
Merged

feat(#738): add criterion benchmark suite for contract hot paths#838
Haroldwonder merged 1 commit into
Haroldwonder:mainfrom
theo372001:feature/issue-738-criterion-benches

Conversation

@theo372001

Copy link
Copy Markdown
Contributor

Description

Adds a criterion benchmark suite that establishes performance baselines for the contract's hot paths, so performance regressions can be tracked between releases (issue #738). The suite covers submit_attestation, get_anchor_health_score, and route_transaction.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD changes
  • Other (please describe):

Related Issues

Closes #738

Changes Made

  • Add benches/hot_paths.rs - a criterion suite benchmarking submit_attestation (auth + ed25519 verify + replay check + storage write), get_anchor_health_score (cached-metadata read + weighted scoring), and route_transaction (anchor filtering + quote selection, parameterized over anchor-set sizes 1 / 5 / 10 / 25).
  • Re-export AnchorKitContractClient and the routing/metadata types (RoutingOptions, RoutingRequest, AnchorMetadata) from the crate root so the benches can drive the contract through the Soroban test harness as an external consumer (these were previously reachable only from #[cfg(test)] modules).
  • Add criterion as a dev-dependency and a [[bench]] target (harness = false).
  • Add a [profile.bench] override (opt-level = 3); the release profile is tuned for wasm size (opt-level = "z"), not native execution speed.
  • Add a make bench target and document the suite in the README.

Testing

  • Unit tests pass (cargo test)
  • Integration tests pass
  • Manual testing performed
  • No tests required (documentation, CI/CD, etc.)

NOTE: cargo bench / cargo test could not be run because the library does not currently compile due to pre-existing, unrelated errors that are also present on main (see Additional Notes). The benchmark suite is self-contained and will run once the library compiles.

Test Coverage

  • Test coverage maintained or improved
  • New tests added for new functionality

This PR adds benchmarks (additive, no source-logic changes), not unit tests, so functional coverage is unchanged.

Documentation

  • Documentation updated (if applicable)
  • No documentation changes needed
  • Documentation will be added in a follow-up PR

Breaking Changes

  • No breaking changes
  • Breaking changes (please describe):

Library changes are limited to additive pub use re-exports.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

The branch does not compile yet because of pre-existing, unrelated build errors in the library, present on main as well and untouched by this PR - for example:

  • invalid match patterns in src/retry.rs (ErrorCode::X as u32 used as a pattern),
  • a missing mod sep6; declaration in src/lib.rs (which has pub use sep6::{...}),
  • duplicate revoke_attestation definitions in src/contract.rs.

These need to be resolved separately for the suite to execute via cargo bench (or make bench).

…t paths

Add a benches/ directory with a criterion-based benchmark suite that
establishes performance baselines for the three most performance-sensitive
contract entry points so regressions can be caught between releases:

- submit_attestation (auth + ed25519 verify + storage write)
- get_anchor_health_score (cached-metadata read + weighted scoring)
- route_transaction (anchor filtering + quote selection, parameterized by
  anchor-set size)

The benches drive the contract through the Soroban test harness as an
external consumer of the crate. To support this:

- Re-export AnchorKitContractClient and the routing/metadata types from
  the crate root (previously only reachable via #[cfg(test)] modules).
- Add criterion as a dev-dependency and a [[bench]] target (harness = false).
- Add a [profile.bench] override (opt-level = 3) since the release profile
  is tuned for wasm size, not native execution speed.
- Reproduce the SEP-10 registration / payload-signing helpers locally, as
  their in-crate counterparts are gated behind #[cfg(test)].

Also add a make bench target and document the suite in the README.
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@theo372001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Haroldwonder Haroldwonder merged commit 8a1e8f0 into Haroldwonder:main Jun 29, 2026
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.

Add benchmark suite for contract hot paths using criterion

2 participants