-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(perps): price caching performance issues cp-7.58.0 #22038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #22038 +/- ##
==========================================
- Coverage 77.04% 77.02% -0.03%
==========================================
Files 3765 3805 +40
Lines 95826 97096 +1270
Branches 18616 18928 +312
==========================================
+ Hits 73833 74792 +959
- Misses 16918 17165 +247
- Partials 5075 5139 +64 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…sk-mobile into feat/perps/price-caching
|



Description
This PR fixes a performance regression in the Perps feature introduced in PR #21428 (October 21, 2025) where L2 order book WebSocket subscriptions were created for 100+ markets globally, despite only 2 views needing this data.
What is the reason for the change?
Performance Regression: PR #21428 added
includeOrderBook: trueto ALL price subscriptions (including the prewarm system) to support maker/taker fee calculations. This created unnecessary L2 order book WebSocket subscriptions for 100+ markets on every screen, even though only PerpsOrderView and PerpsClosePositionView actually use bestBid/bestAsk data.Critical Context: This issue is present in release/7.58.0 (about to be submitted). It wasn't detected earlier because it was masked by:
The order book issue would have been obvious in isolation, but was effectively "lost in the noise" of other performance problems.
What is the improvement/solution?
Architectural Fix: Separate order book subscriptions from basic price subscriptions using a dedicated channel:
TopOfBookStreamChannelandusePerpsTopOfBook()hookNote: Renamed to "TopOfBook" (from "OrderBook") to clarify that it provides only best bid/ask (1 level), not full L2 order book with multiple levels. Full L2 order book subscriptions would be a separate feature if needed.
Result: Reduces L2 order book WebSocket subscriptions from 100+ (global) to 2 maximum (on-demand).
Implementation Details
Phase 1: Infrastructure
TopOfBookStreamChannelclass in PerpsStreamManager.tsxusePerpsTopOfBookhook in hooks/stream/TopOfBookDataPhase 2: View Updates
PerpsOrderView.tsxto useusePerpsTopOfBookPerpsClosePositionView.tsxto useusePerpsTopOfBookPhase 3: Cleanup
includeOrderBook: truefrom prewarm subscription (line 357)includeOrderBook: truefrom regular subscriptions (line 250)Phase 4: Testing
topOfBookchannelChangelog
CHANGELOG entry: Fixed Perps performance issue by optimizing order book subscriptions
Related issues
Fixes: Performance regression from PR #21428
Related: Issue present in release/7.58.0
Manual testing steps
Screenshots/Recordings
Before
Video extracted from clean install on
release/7.58.0android_7.58_unusable.mp4
Architecture:
WebSocket Subscriptions: 100+ L2 order book subscriptions created on connection
Performance: Views processing unnecessary order book data for markets they don't display
After
android_fix_performance.mp4
Architecture:
WebSocket Subscriptions: Max 2 L2 order book subscriptions (only when OrderView or ClosePositionView is active)
Performance: Views only process data they actually need
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduces a dedicated top-of-book stream/hook used by order/close views, removes global L2 order book from price subscriptions, and optimizes price/throttle handling.
TopOfBookStreamChannelinPerpsStreamManagerandusePerpsTopOfBookhook; subscribes per-symbol withincludeOrderBook: true, caches best bid/ask, and cleans up on unmount.includeOrderBookfrompricessubscriptions and prewarm; keep basic price data only.StreamChannel; memoizeusePerpsLivePricesdependencies; optimizeHyperLiquidSubscriptionService.allMidsto process only subscribed symbols and skip unchanged prices before notifying.PerpsOrderView.tsxandPerpsClosePositionView.tsxto useusePerpsTopOfBookfor maker/taker fee inputs (currentBidPrice/currentAskPrice).usePerpsTopOfBooktests andTopOfBookStreamChanneltests; update mocks (defaultPerpsTopOfBookMock) and view tests to wire new hook; markperps-add-funds.spec.tstest asit.skip.Written by Cursor Bugbot for commit 9216fff. This will update automatically on new commits. Configure here.