feat: implement resource-cost benchmark harness and optimizations - #376
Open
dev-king-001 wants to merge 10 commits into
Open
feat: implement resource-cost benchmark harness and optimizations#376dev-king-001 wants to merge 10 commits into
dev-king-001 wants to merge 10 commits into
Conversation
What was done - Added benchmark tests in budget.rs - Configured CI regression gate check_metrics.js - Optimized payout loop and amounts logic - Optimized distribute_recursive tree traversal Why it was done To monitor cost worst cases and prevent silent limits regressions. How it was verified Ran benchmark tests and manually reviewed optimizations. Closes tributary-protocol#353
…el to stay within limits
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.
What this changes
contracts/splitter/src/test/budget.rs) that explicitly tests and measures worst-case routing scenarios (32-recipient payouts, deep nested trees, largepay_manybatches).scripts/check_metrics.jsandci.yml) that asserts benchmark costs against a committedbaseline.json, failing the build if there is a >5% cost regression.payoutloop by computing fractional shares inline, completely eliminating a redundantVec<i128>allocation and a secondO(N)loop iteration over recipients.distribute_recursiveto skip re-running expensive 256-bit math just to route cascaded funds, relying instead on a single storage read check per child.Why
Soroban's CPU, memory, and read/write footprint limits mean that a small overhead addition to a loop could silently push worst-case 32-recipient payouts past the max ledger budget, effectively bricking large splits in production. This establishes a standing, enforced cost budget that catches regressions in code review rather than on-chain. The optimization pass provides a wider safe-operating envelope for developers batching distributions.
Checklist
cargo fmt --allandcargo clippy --all-targets -- -D warningspasscargo testpasses