Skip to content

perf: memoize Horizon/RPC server instances across all hooks - #390

Open
SURUJ404 wants to merge 1 commit into
dark-princezz:mainfrom
SURUJ404:fix/memoize-server-instances
Open

perf: memoize Horizon/RPC server instances across all hooks#390
SURUJ404 wants to merge 1 commit into
dark-princezz:mainfrom
SURUJ404:fix/memoize-server-instances

Conversation

@SURUJ404

@SURUJ404 SURUJ404 commented Jul 27, 2026

Copy link
Copy Markdown

28 hooks now share one \Horizon.Server\ /
pc.Server\ per URL instead of creating new instances per call.

Before:
ew Horizon.Server(url)\ /
ew rpc.Server(url)\ in every hook → no connection reuse.
After: \getHorizonServer(url)\ / \getRpcServer(url)\ from \src/utils/memoizedServers.ts\ — already used by \useNetworkStatus\ + \useStellarAccount, now applied to all 28 remaining hooks.

Replace direct
ew Horizon.Server(url) /
ew rpc.Server(url) calls
with shared getHorizonServer(url) / getRpcServer(url) from
src/utils/memoizedServers.ts across all 29 sites in the codebase.

Previously each hook created its own SDK server instance per invocation,
defeating connection pooling and causing unnecessary object allocation.
The memoized versions cache instances by URL, so all hooks sharing the
same network config reuse a single Horizon.Server and rpc.Server.

Files changed: useAccountFlags, useAccountMerge, useAssets,
useBumpSequence, useClaimableBalance, useEffects, useHorizonServer,
useInflation, useLedgerEntry, useManageData, useMultiSig, useOfferBook,
useOperations, useOrderBook, usePathPayment, usePayment,
useSorobanContract, useSorobanServer, useSorobanTokenBalance,
useStellarOffers, useStellarTransaction, useStrictSendPaths, useTrade,
useTrades, useTransaction, useTransactionCore, useTrustline,
useTrustlines.
@SURUJ404 SURUJ404 changed the title perf: memoize Horizon and RPC server instances across all hooks perf: memoize Horizon/RPC server instances across all hooks Jul 27, 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.

1 participant