Skip to content

feat: improve performance in utils.ts and streams.ts with caching and precomputation - #405

Merged
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
Viky207:feat/module-40-50-performance-tests-docs
Jul 30, 2026
Merged

feat: improve performance in utils.ts and streams.ts with caching and precomputation#405
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
Viky207:feat/module-40-50-performance-tests-docs

Conversation

@Viky207

@Viky207 Viky207 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issues #374 and #384 with the following changes:

Performance Improvements

utils.ts (module 40):

  • Precomputed POW10 lookup table for decimal values 0–19, eliminating repeated BigInt(10 ** decimals) computation on every call to toStroops, fromStroops, calculateRate, and calculateYield
  • Optimized toStroops to avoid intermediate string allocations (uses charCodeAt instead of Number() conversion)
  • Optimized fromStroops to avoid regex for trimming trailing zeros (uses character code comparison loop)
  • Optimized calculateRate to compute remainder via subtraction instead of separate modulo operation

streams.ts (module 50):

  • Cached caller address in _resolveCallerAddress() to avoid redundant getPublicKey() calls on every read/mutating operation; cache is invalidated on setWallet()
  • Cached SorobanRpc.Server proxy in _server() to avoid recreating the Proxy wrapper on every RPC call

Unit Tests

  • Added tests for toStroops and fromStroops with non-default decimal values (0, 1, 8, 18)
  • Added tests for calculateRate with non-default decimals
  • Added tests for bigintSafeStringify edge cases (empty object, empty array, deeply nested values)
  • Added tests for caller address caching and cache invalidation via setWallet()
  • Added tests for server instance caching

Documentation

  • Updated docs/architecture.md to document the caching and performance optimizations
  • Updated docs/api.md to document the precomputation and caching improvements

Closes #374
Closes #384
Closes #40
Closes #50

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

Viky207 and others added 2 commits July 30, 2026 14:43
… 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
Jaydbrown force-pushed the feat/module-40-50-performance-tests-docs branch from 420a718 to b29ec55 Compare July 30, 2026 13:52
@Jaydbrown
Jaydbrown merged commit 6cc044e into conduit-protocol:main Jul 30, 2026
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.

Enhancement: Detailed SDK Feature #50 Enhancement: Detailed SDK Feature #40

3 participants