perf: reduce RELEASE_HISTORY reads from O(N) to O(1) in release_schedule#1430
Merged
Jagadeeshftw merged 2 commits intoJun 28, 2026
Conversation
|
@BigMick03 is attempting to deploy a commit to the Jagadeesh B's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@BigMick03 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! 🚀 |
…e-single-read-optimization
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.
Closes #1385
Pull Request
Title
perf: reduce RELEASE_HISTORY reads from O(N) to O(1) in
release_scheduleSummary
Overview
This PR optimizes the
release_schedulefunction incontracts/program-escrow/src/lib.rsby eliminating repeated reads of theRELEASE_HISTORYstorage key.Previously, the function performed one storage read per schedule entry, resulting in O(N) ledger reads for N due milestones. This implementation now follows a load-once, mutate-in-memory, write-once pattern, reducing storage I/O for the history record to O(1).
This optimization lowers ledger entry access fees, improves execution efficiency for schedules with many milestones, and preserves existing contract behavior.
Changes
Performance Improvements
Load
RELEASE_HISTORYonce at the beginning ofrelease_scheduleProcess all due schedule entries using an in-memory
VecMark processed entries as released without additional storage reads
Persist the updated history only once after processing
Skip storage writes when no entries require updates
Files Modified
Contract
Tests
Documentation
Implementation Details
Before
Storage complexity:
Reads: O(N)
Writes: O(N)
After
Storage complexity:
Reads: O(1)
Writes: O(1) (only when updates occur)
Benefits
Reduces ledger storage access
Lowers execution costs
Improves scalability for large release schedules
Maintains existing contract behavior
Easier to review and maintain
Security Considerations
The optimization preserves the existing release logic while reducing storage operations.
Security validations include:
No change to authorization rules
No modification of release conditions
Release order remains deterministic
Duplicate releases remain prevented
State consistency maintained during batch processing
Storage is written only after successful in-memory processing
No additional attack surface introduced
Testing
Added comprehensive tests covering:
Single milestone release
Multiple due milestones
Large release schedules
Empty release history
No eligible milestones
Already released milestones
Partial releases
Consecutive batch releases
State persistence after write
Ledger history integrity
Edge Cases
Verified behavior for:
Empty schedule
Empty history vector
One release
Hundreds of release entries
Duplicate release attempts
All milestones already released
Future milestones only
Mixed due and pending milestones
Failed execution paths
No-op execution (no storage write)
Documentation
Added:
Documentation includes:
Motivation
Performance analysis
Storage complexity comparison
Implementation details
Security assumptions
Testing strategy
Future optimization opportunities
NatSpec Documentation
Added NatSpec-style documentation covering:
Function purpose
Parameters
Return values
Storage behavior
Complexity analysis
Security guarantees
Test Results
Executed:
Expected outcome:
Performance Comparison
*Write occurs only if one or more entries were updated.
Reviewer Checklist
Storage read optimization verified
Single-write pattern confirmed
Contract behavior unchanged
Security assumptions reviewed
NatSpec documentation added
Documentation complete
Edge cases tested
Test suite passes
Performance improvement validated
Code style follows project conventions
Coverage
Target test coverage: ≥95%
Existing functionality preserved
New optimization paths fully tested
Example Commit Message
Estimated Completion
96 hours