Skip to content

feat: implement resource-cost benchmark harness and optimizations - #376

Open
dev-king-001 wants to merge 10 commits into
tributary-protocol:mainfrom
dev-king-001:main
Open

feat: implement resource-cost benchmark harness and optimizations#376
dev-king-001 wants to merge 10 commits into
tributary-protocol:mainfrom
dev-king-001:main

Conversation

@dev-king-001

Copy link
Copy Markdown
Contributor

What this changes

  • Introduces a resource-cost benchmark harness (contracts/splitter/src/test/budget.rs) that explicitly tests and measures worst-case routing scenarios (32-recipient payouts, deep nested trees, large pay_many batches).
  • Implements a CI regression gate (scripts/check_metrics.js and ci.yml) that asserts benchmark costs against a committed baseline.json, failing the build if there is a >5% cost regression.
  • Significantly optimizes the payout loop by computing fractional shares inline, completely eliminating a redundant Vec<i128> allocation and a second O(N) loop iteration over recipients.
  • Optimizes distribute_recursive to 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

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
@dev-king-001
dev-king-001 requested a review from Spagero763 as a code owner July 23, 2026 14:00
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.

Resource-cost benchmark harness with a CI regression gate on worst-case payouts

2 participants