feat: improve performance in utils.ts and streams.ts with caching and precomputation - #405
Merged
Jaydbrown merged 2 commits intoJul 30, 2026
Conversation
|
@Viky207 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! 🚀 |
… precomputation - Precompute POW10 lookup table in utils.ts to eliminate repeated BigInt(10 ** decimals) computation - Cache caller address in StreamsModule to avoid redundant getPublicKey() calls - Cache SorobanRpc.Server proxy in StreamsModule to avoid recreating Proxy wrapper - Add unit tests for POW10 optimization with non-default decimals - Add unit tests for caller address caching and server caching - Update docs/api.md and docs/architecture.md to document caching and performance improvements Closes conduit-protocol#374 Closes conduit-protocol#384 Closes #40 Closes #50
- streams.test.ts's new caching tests referenced undefined helpers
(STREAM_ADDR, simSuccess, mockGetTransaction, txSuccess) left over from
a different test context, and accessed private _resolveCallerAddress()/
_server() without the (sdk as any) cast this codebase's other tests use
for private-member access. Neither test actually needs RPC/tx mocking:
both are pure caching-behavior checks.
- utils.test.ts's two new decimals=8 tests had hand-miscalculated expected
values (e.g. toStroops('1.000000005', 8) asserted as 1000000005n, but
1.000000005 has 9 fractional digits against decimals=8 so it takes the
rounding path and correctly yields 100000001n -- confirmed by hand and
against the unchanged original algorithm). Switched to an unambiguous
8-fractional-digit input for both directions.
Jaydbrown
force-pushed
the
feat/module-40-50-performance-tests-docs
branch
from
July 30, 2026 13:52
420a718 to
b29ec55
Compare
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.
This PR addresses issues #374 and #384 with the following changes:
Performance Improvements
utils.ts (module 40):
BigInt(10 ** decimals)computation on every call totoStroops,fromStroops,calculateRate, andcalculateYieldtoStroopsto avoid intermediate string allocations (usescharCodeAtinstead ofNumber()conversion)fromStroopsto avoid regex for trimming trailing zeros (uses character code comparison loop)calculateRateto compute remainder via subtraction instead of separate modulo operationstreams.ts (module 50):
_resolveCallerAddress()to avoid redundantgetPublicKey()calls on every read/mutating operation; cache is invalidated onsetWallet()SorobanRpc.Serverproxy in_server()to avoid recreating the Proxy wrapper on every RPC callUnit Tests
toStroopsandfromStroopswith non-default decimal values (0, 1, 8, 18)calculateRatewith non-default decimalsbigintSafeStringifyedge cases (empty object, empty array, deeply nested values)setWallet()Documentation
docs/architecture.mdto document the caching and performance optimizationsdocs/api.mdto document the precomputation and caching improvementsCloses #374
Closes #384
Closes #40
Closes #50