Skip to content

perf: add RPC server instance cache to eliminate per-call HTTP agent … - #386

Merged
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
OMGO-Code:feat/381-detailed-sdk-feature
Jul 30, 2026
Merged

perf: add RPC server instance cache to eliminate per-call HTTP agent …#386
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
OMGO-Code:feat/381-detailed-sdk-feature

Conversation

@OMGO-Code

Copy link
Copy Markdown
Contributor

…creation

All SDK functions that interact with the Soroban RPC were creating a new SorobanRpc.Server instance on every call, which meant a new HTTP agent (and TCP/TLS handshake) per operation. For operations like list() that issue N+1 calls, this added significant overhead.

Changes:

  • Add getServer(rpcUrl) with a module-level Map cache in soroban.ts
  • Add clearServerCache() for test teardown and config changes
  • Refactor buildContractCallTx, invokeContract, simulateReadOnly to use cache
  • Refactor StreamsModule._server() to delegate to getServer()
  • Refactor events.ts subscribeToStream to use getServer()
  • Export getServer/clearServerCache from the public API
  • Add 10 unit tests covering cache hit, miss, clear, and integration
  • Document RPC Server Lifecycle in docs/api.md and docs/architecture.md

Closes #381

What does this PR do?

Type of change

  • Bug fix
  • New feature / method
  • Refactor
  • Test coverage
  • Documentation
  • Dependency update

Related issue

Closes #

Changes

File Change

Checklist

  • npm run typecheck — no errors
  • npm run lint — no warnings
  • npm test — all tests pass
  • npm run build — bundle compiles cleanly
  • No any types introduced
  • New public methods documented in docs/api.md
  • All on-chain amounts kept as bigint — no Number() conversion in arithmetic
  • New methods mock-tested in src/tests/
  • CHANGELOG.md updated under [Unreleased]
  • src/index.ts updated if new exports added

Breaking changes?

  • No
  • Yes — describe below and add BREAKING CHANGE: footer to relevant commit

Notes for reviewers

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@OMGO-Code 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

OMGO-Code and others added 2 commits July 30, 2026 07:13
…creation

All SDK functions that interact with the Soroban RPC were creating a new
SorobanRpc.Server instance on every call, which meant a new HTTP agent
(and TCP/TLS handshake) per operation. For operations like list() that
issue N+1 calls, this added significant overhead.

Changes:
- Add getServer(rpcUrl) with a module-level Map cache in soroban.ts
- Add clearServerCache() for test teardown and config changes
- Refactor buildContractCallTx, invokeContract, simulateReadOnly to use cache
- Refactor StreamsModule._server() to delegate to getServer()
- Refactor events.ts subscribeToStream to use getServer()
- Export getServer/clearServerCache from the public API
- Add 10 unit tests covering cache hit, miss, clear, and integration
- Document RPC Server Lifecycle in docs/api.md and docs/architecture.md

Closes conduit-protocol#381
…onduit-protocol#392

createRpcServer() (the retry-with-backoff wrapper all SDK internals actually
use to construct RPC servers) now gets its base SorobanRpc.Server from this
PR's getServer() cache instead of always constructing a new one, so callers
get both the caching and the automatic rate-limit retry together rather than
having to choose one or the other.

Also:
- Remove an unused `getServer` import left over from the rebase in
  streams.ts (createRpcServer already covers it).
- Fix the docs' "Internal usage" note, which said internal SDK code uses
  getServer() directly — it actually goes through createRpcServer(), which
  adds retry-with-backoff on top; getServer() alone gives the cached
  instance with no retry.
- Drop an unused `xdr` import in the new soroban-server-cache.test.ts.

Verified: full lint/typecheck/vitest clean (547 tests passing).
@Jaydbrown
Jaydbrown force-pushed the feat/381-detailed-sdk-feature branch from 2c2a03b to f3c93d4 Compare July 30, 2026 06:18
@Jaydbrown
Jaydbrown merged commit 1e36d3e 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 #47

3 participants