Skip to content

perf(runtime): add configurable Pedersen memoization - #1

Open
heemankv wants to merge 4 commits into
madara-cairo-native-0.9.0-rc.6from
perf/pedersen-cache-runtime-config
Open

heemankv wants to merge 4 commits into
madara-cairo-native-0.9.0-rc.6from
perf/pedersen-cache-runtime-config

Conversation

@heemankv

@heemankv heemankv commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add opt-in memoization for Cairo Native runtime Pedersen hashing
  • keep cache configuration, storage, counters, and focused tests isolated in src/pedersen_cache.rs; runtime.rs only performs cache lookup and insertion around the Pedersen call
  • replace the hard-coded active capacity with startup configuration supplied by downstream Madara
  • keep the default disabled and expose an 8,192-entry default capacity per native execution thread
  • expose process-wide cumulative hit, miss, total-call, and capacity-clear snapshots using relaxed atomics
  • retain set_pedersen_cache_enabled(bool) for compatibility while adding the complete configure_pedersen_cache(...) API

The cache remains thread-local for the native execution hot path. Its configured capacity therefore applies independently to each native worker thread, while the telemetry aggregates activity across the process.

Exact Madara dependency base

This PR is intentionally based on 7e263feb594cf95e0ec000a83520b9ed5c827855, the commit tagged v0.9.0-rc.6.

That is the exact source release resolved as cairo-native 0.9.0-rc.6 in madara-alliance/madara@daaacf0055fbea1dca67b49aab5a74426efbf49c. The PR base branch points directly to that tag commit, so the diff remains limited to the Pedersen-cache work needed by Madara.

Validation

  • cargo test pedersen_cache: 2 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: passed
  • cargo fmt --all -- --check: passed
  • git diff --check: passed
  • downstream locked cargo check -p mc-exec: passed
  • downstream locked cargo check -p madara: passed

Downstream integration: madara-alliance/madara#1250

@heemankv
heemankv force-pushed the perf/pedersen-cache-runtime-config branch from 454d432 to 76dec03 Compare August 31, 2026 17:54

@Mohiiit Mohiiit 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.

I didn't find a merge-blocking Rust correctness issue at this head. I left two non-blocking questions inline.

Comment thread src/pedersen_cache.rs
Comment thread src/pedersen_cache.rs Outdated

@Mohiiit Mohiiit 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.

The two review questions are addressed at this head, and I didn't find additional blocking issues.

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.

2 participants