refactor: PerpsSection performance improvements#26973
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. |
9663f9c to
8b07253
Compare
8b07253 to
d547c40
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
Ramps team already has caching on the controller for all ramp endpoints getting hit through the client. Do you think we still want to do this as this might be redundant in a week? |
Nope, it's a very small improvement, so it can easily wait for a more refined solution from your team 👍 |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag Selection Rationale:
The changes are defensive and performance-focused, but the removal of live prices from PerpsMarketTileCard is a behavioral change that warrants testing. The defensive null checks in selectors could affect how the app behaves during initialization or with minimal E2E fixtures. Performance Test Selection: |
The committed fixture schema is out of date. To update, comment: |
|



Description
Perpetuals section – performance and stability
Performance audit follow-up: fewer re-renders, no redundant subscriptions on the homepage, and safer selectors/hooks.
Homepage Perps
PerpsMarketTileCard. Tiles use the market snapshot fromusePerpsMarkets()(price, change24hPercent). No WebSocket per symbol on the homepage; fewer subscriptions and re-renders.livePrices/disableLivePrices; component always uses static market data. RemovedTileCardWithLivePricesandusePerpsLivePricesusage there.PositionCardItemwith apositionDisplayKey(symbol, entryPrice, size, unrealizedPnl, takeProfitPrice, stopLossPrice) and customReact.memocompare so only cards whose display data changed re-render on stream updates.?? []for watchlist/carousel arrays andcarouselSymbolsso selectors or partial state (e.g. E2E/minimal fixtures) never passundefinedinto hooks or.map().useHomepageSparklines: guardcandleData?.candles(fixes E2E crash whencandlesis undefined),safeSymbolssosymbolsis never undefined, and microtask batching so multiple symbol callbacks trigger one state update.Perps selectors & components
undefinedand normalizes return values (?? []/ default prefs).React.memoto avoid unnecessary re-renders when parent updates.savedSortPreference.optionIdcast toSortOptionIdfor type safety.Tests
positionDisplayKey(stable key, optional fields, TP/SL, same key when only non-display fields differ).actwhere needed for microtask-flushed updates.useFocusEffectmock simplified (invoke callback once).Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-512
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Moderate risk because it changes rendering/memoization behavior and introduces a module-level TTL cache that could cause stale data or missed UI updates if the cache keys/comparators are wrong.
Overview
Perps homepage performance improvements. Position/order rows now avoid unnecessary re-renders via
React.memo(including a newpositionDisplayKeycomparator) and null-safe carousel list handling;PerpsCard/PerpsPositionCardare also exported as memoized components.Trending carousel simplification.
PerpsMarketTileCardno longer subscribes to live prices and drops thedisableLivePricesprop; it always renders from the passed market snapshot, and tests are updated accordingly.Fewer update storms.
useHomepageSparklinesbatches per-symbol candle callbacks into a single microtask-flushed state update, and related tests are adjusted.Stability + networking. Perps Redux selectors now defensively default/guard against missing controller state, and
useRampTokensadds a 5-minute, module-level cache that deduplicates identical requests (including in-flight), with comprehensive cache behavior tests.Written by Cursor Bugbot for commit 49cecc3. This will update automatically on new commits. Configure here.