feat: add credential performance benchmarks and optimize storage#111
Merged
Josie123-Dev merged 1 commit intoJun 21, 2026
Conversation
…torage Add a benchmark suite for the credential (Verification) contract and fix the storage scaling bottleneck it surfaced. - contracts/src/benchmarks.rs: measure per-operation budget (CPU instructions / memory bytes via env.budget()), execution time, and load behaviour. The benchmarks run as ordinary `cargo test` tests and assert resource ceilings, so they double as regression guards. - Bottleneck found: per-credential records were stored in instance storage, which serialises the entire contract data set on every call — O(n) per op, O(n^2) in aggregate (the 100th credential cost ~51x the 1st). - Optimization: move per-credential data to persistent storage keyed individually via a typed DataKey enum, with TTL bumping; keep only the bounded counter in instance storage. Public API is unchanged. N=100 batch cost drops 6.6x (CPU) and 4.0x (memory); reads get 26-30% cheaper. - docs/PERFORMANCE.md: methodology, before/after results, and remaining recommendations. README points to it. Closes GuardZero144#100
|
@nanlebenthel-web is attempting to deploy a commit to the Josie's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a performance benchmark suite for the credential (
Verification) contract and fixes the storage scaling bottleneck the benchmarks revealed.What's included
contracts/src/benchmarks.rs): measures per-operation budget cost (CPU instructions + memory bytes viaenv.budget()), execution time, and load behaviour. They run as normalcargo testtests and assert resource ceilings, so they double as regression guards.DataKeyenum, with TTL bumping; only the bounded counter stays in instance storage. Public API is unchanged.docs/PERFORMANCE.md): methodology, the native-host caveat, before/after results, and remaining recommendations. README points to it.Measured impact (native test host)
get_verificationreadis_verification_validreadHow to run
Test plan
cargo test --features testutils— all 78 tests pass (incl. 5 benchmarks + existing suite)cargo fmt -- --checkcleancargo clippy --all-targets -- -D warningscleancargo build --release --target wasm32-unknown-unknownsucceedsAcceptance criteria
docs/PERFORMANCE.md)Closes #100