fix(perps): optimize connection speed and consolidate architecture cp-7.57.0#20946
Merged
Conversation
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
333f29d to
ec341e2
Compare
gambinish
reviewed
Oct 9, 2025
e81cb84 to
0ff076f
Compare
…/optimize-connection2
|
Matt561
approved these changes
Oct 14, 2025
Matt561
left a comment
Contributor
There was a problem hiding this comment.
Tests well on iOS and Android low spec device 👍
Dismissing my comment since this bug is now fixed with the Sentry fix
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.




Description
Second part of Perps connection optimizations building on PR #20918. This PR delivers performance improvements, reliability fixes, and architectural cleanup for the Perps connection system.
Performance (TAT-1576): Faster HyperLiquid Connection
Replaced blocking
getAccountState()API calls with lightweight WebSocket health checks:provider.ping()WebSocket health check (5s timeout) instead of full API callsAccount data is now efficiently fetched via WebSocket subscriptions during preload, eliminating blocking HTTP requests and retry logic.
Reliability Improvements
Connection timeout protection (TAT-1576):
CONNECTION_TIMEOUTerror codeBackground reconnection fix (TAT-1559):
Architecture: Error Logging & Code Consolidation
getErrorContext()helper and comprehensive Sentry logging to 20+ catch blocks with consistent context (feature, context, provider, network)perps_x_ytoperps.x.yfor hierarchical grouping and easier filtering in Sentry dashboardsController.reconnectWithNewContext()- Manager callsinitializeProviders()directlyreconnectWithNewContext({ force: true })for proper WebSocket disconnectusePerpsConnectionhook to separate file, addedReconnectOptionsinterfacePERPS_CONNECTION_ARCHITECTURE.mdwith Mermaid diagrams explaining connection lifecycle and race condition handlingImpact:
Changelog
CHANGELOG entry: null
Related issues
Depends on: #20918
Fixes: TAT-1576, TAT-1559
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Notes for Reviewers
Key Changes
Performance (TAT-1576):
PerpsConnectionManager.ts: Removed blockinggetAccountState()HTTP calls and retry logicprovider.ping()WebSocket health check (5s timeout)streamManager.account.prewarm()during preload subscriptionsReliability:
CONNECTION_TIMEOUTerror codeError Logging:
getErrorContext()helper for consistent Sentry context across 20+ catch blocksperps.{category}.{metric}format for better Sentry dashboardsperps_websocket_connection→perps.websocket.connection_establishmentArchitecture:
hooks/usePerpsConnection.ts- Extracted hook from providerdocs/perps/PERPS_CONNECTION_ARCHITECTURE.md- Architecture guide with Mermaid diagramstypes/index.ts- AddedReconnectOptionsinterfaceController.reconnectWithNewContext()- Manager now callsinitializeProviders()directlyreconnectWithNewContext({ force: true })Testing Focus Areas
Note
Replaces blocking HTTP checks with a WS ping for faster connects, adds 30s connection timeout and 300ms foreground delay, consolidates error logging/metrics, and refactors connection APIs/hooks.
getAccountState()health checks withprovider.ping()WS health check; remove stale-connection HTTP checks.CONNECTION_TIMEOUT) and 300ms post-foreground delay; preload account data via subscriptions.PerpsController.reconnectWithNewContext; Manager now callsinitializeProviders(); retry usesreconnectWithNewContext({ force: true }).usePerpsConnectionhook; addReconnectOptions; switch imports from provider to hook.ensureError()and controller/providergetErrorContext(); update 20+ catch blocks.perps.*(e.g.,perps.websocket.*,perps.screen.*).ping(timeoutMs?)inHyperLiquidProvider; add WS client typing; improve subscription error handling.PerpsStreamManagerand subscription services (error logging, cache/prewarm cleanup).PERPS_CONSTANTS(timeouts, ping); addconnectionTimeouti18n string.Written by Cursor Bugbot for commit db00eee. This will update automatically on new commits. Configure here.