perf: memoize Horizon/RPC server instances across all hooks - #390
Open
SURUJ404 wants to merge 1 commit into
Open
perf: memoize Horizon/RPC server instances across all hooks#390SURUJ404 wants to merge 1 commit into
SURUJ404 wants to merge 1 commit into
Conversation
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.
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.
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.