Skip to content

feat: perf: optimize contract storage access patterns#946

Merged
Xoulomon merged 2 commits into
Xoulomon:mainfrom
Mirabliss:perf/optimize-contract-storage-access
May 30, 2026
Merged

feat: perf: optimize contract storage access patterns#946
Xoulomon merged 2 commits into
Xoulomon:mainfrom
Mirabliss:perf/optimize-contract-storage-access

Conversation

@Mirabliss
Copy link
Copy Markdown
Contributor

Audit and fix three redundant/expensive storage reads:

  1. join_group: remove redundant GroupStatus SLOAD

    • Previously loaded group.status via a separate status_key SLOAD
    • Now reads group.status from the already-loaded Group struct
    • Saves 1 persistent SLOAD per join_group call
  2. contribute: move reentrancy guard to temporary storage

    • Temporary storage is ~10x cheaper than persistent on Soroban
    • Guard is auto-cleared at ledger close; no persistent slot needed
    • Saves ~3 persistent storage ops per contribute call
  3. execute_payout: move reentrancy guard to temporary storage

    • Same fix as contribute() — guard moved from persistent to temporary
    • Saves ~2 persistent storage ops per payout call
  4. gas_benchmark: update op counts and assertions to reflect new savings

    • contribute() persistent ops: 19 before -> 13 after (31% reduction)
    • Benchmark table updated with accurate post-optimization counts

Summary

Motivation

Closes #

Type of change

  • feat — new feature
  • fix — bug fix
  • docs — documentation only
  • refactor — code restructuring, no behaviour change
  • test — tests only
  • chore — build, deps, tooling
  • perf — performance improvement
  • Breaking change (existing behaviour changes)

Changes

Testing

Smart contract:

cargo test -p stellar-save

Frontend:

cd frontend && npm test run

Manual steps (if applicable):

Checklist

  • cargo fmt run (Rust changes)
  • cargo clippy -- -D warnings passes (Rust changes)
  • npm run lint passes (frontend changes)
  • Tests added or updated for new/changed behaviour
  • CI is green
  • Documentation updated (if behaviour changed)
  • No secrets or .env files staged

Screenshots / recordings

closes #894

Audit and fix three redundant/expensive storage reads:

1. join_group: remove redundant GroupStatus SLOAD
   - Previously loaded group.status via a separate status_key SLOAD
   - Now reads group.status from the already-loaded Group struct
   - Saves 1 persistent SLOAD per join_group call

2. contribute: move reentrancy guard to temporary storage
   - Temporary storage is ~10x cheaper than persistent on Soroban
   - Guard is auto-cleared at ledger close; no persistent slot needed
   - Saves ~3 persistent storage ops per contribute call

3. execute_payout: move reentrancy guard to temporary storage
   - Same fix as contribute() — guard moved from persistent to temporary
   - Saves ~2 persistent storage ops per payout call

4. gas_benchmark: update op counts and assertions to reflect new savings
   - contribute() persistent ops: 19 before -> 13 after (31% reduction)
   - Benchmark table updated with accurate post-optimization counts
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Mirabliss 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

@Xoulomon Xoulomon merged commit 7ba9173 into Xoulomon:main May 30, 2026
13 of 39 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.

[Performance] Optimize contract storage access patterns

2 participants