Skip to content

fix: oversubscription perps top movers#33150

Draft
gambinish wants to merge 4 commits into
mainfrom
fix/oversubscription-perps-top-movers
Draft

fix: oversubscription perps top movers#33150
gambinish wants to merge 4 commits into
mainfrom
fix/oversubscription-perps-top-movers

Conversation

@gambinish

@gambinish gambinish commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

Problem

The Now-tab perps movers strip subscribed to live prices for all ~329 markets and, on every ~3s push, rebuilt/re-sorted the full set and re-rendered — just to show the top 12 pills. Since Explore tabs never unmount, this kept running even on other tabs or after leaving Explore.

Why we keep the full-market subscription

Subscribing to only the 12 displayed symbols would break ranking: a market outside the top 12 can move into it, and we'd miss that price change. Correct live re-ordering requires watching every market.

The middle ground

The WebSocket already pushes all markets regardless of subscription — the real cost was the unconditional setState and new object identities per tick. The new usePerpsLiveMovers hook keeps watching all markets at the ref level (no render per tick) and only commits state when the displayed top-12 actually changes (via a symbol:formattedPercent fingerprint), reusing prior item references so unchanged pills skip re-render. Idle ticks are effectively free.

On top of that, the subscription now pauses entirely when not visible: an ExploreActiveTabContext tells PerpsBlock whether the Now tab is active, combined with useIsFocused() for leaving Explore. The same focus gating is applied to the What's Happening detail view's perps price hook. Disabling freezes the last-known data rather than clearing it, so nothing blanks out and it refreshes immediately on resume.

Changelog

CHANGELOG entry:

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@mm-token-exchange-service mm-token-exchange-service Bot added the team-perps Perps team label Jul 10, 2026
@mm-token-exchange-service

mm-token-exchange-service Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Blocking — these items fail the workflow until fixed:

  • Changelog section has an empty CHANGELOG entry: line. Fill in a description, write CHANGELOG entry: null, or apply the no-changelog label.

Warnings — informational, address before merging:

  • Description section is empty. Describe what changed and why.
  • Related issues section is empty. Add Fixes: #123 / Closes: <URL> / Refs: <Jira key>, or write a short rationale after the colon.
  • Manual testing steps still contain template content (the Gherkin example title or a [...] placeholder). Replace with real steps, or write N/A — <reason>.
  • Screenshots/Recordings section is empty. Add an image/video for user-facing changes, logs/console output for non-user-facing changes, or write N/A if no evidence is applicable.
  • Pre-merge author checklist has unchecked items (e.g. "I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards."). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeWalletPlatform, SmokePerps, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR introduces:

  1. A new ExploreActiveTabContext to track the active Explore tab and pause live WebSocket subscriptions when tabs are not visible.
  2. A new usePerpsLiveMovers hook that efficiently ranks perps markets by live 24h price-change with an enabled flag to freeze updates when hidden.
  3. Refactoring of NowTab.tsx PerpsBlock to use the new hook and pause subscriptions when the screen is unfocused or the Now tab is not active.
  4. useWhatsHappeningAssetPrices.ts now pauses perps price subscriptions when the detail view is not focused.

These changes directly affect:

  • The Perps section within the Trending/Now tab (gainers/losers movers display) → SmokePerps
  • The Trending tab overall (ExploreActiveTabProvider wraps all tabs) → SmokeWalletPlatform
  • Per SmokePerps tag description: when selecting SmokePerps, also select SmokeWalletPlatform and SmokeConfirmations (Add Funds deposits are on-chain transactions)

The changes are functional refactors (not purely cosmetic) that could affect subscription lifecycle, rendering behavior, and data display in the Perps movers section. Risk is medium as the logic changes are contained to the Trending/Perps area but involve WebSocket subscription management which could have subtle bugs.

Performance Test Selection:
The PR refactors how perps live price subscriptions are managed in the Trending/Now tab. The new usePerpsLiveMovers hook introduces a fingerprint-based optimization to avoid unnecessary re-renders on WebSocket ticks, and the enabled flag pauses subscriptions when the tab is not active. These changes could impact the performance of the Perps section rendering (movers list updates, subscription overhead). The @PerformancePreps tag covers perps market loading and position management which is directly affected by these subscription and rendering optimizations.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Performance Test Results

ℹ️ Performance test results are currently non-blocking and will not block this PR.

1 test failed · 2 tests · 1 device

📱 Devices tested (1)

Android: Google Pixel 8 Pro (v14.0)

❌ Failed Tests (1)

@mm-perps-engineering-team

Test Platform Device Reason Recording
Perps open position and close it Android Google Pixel 8 Pro (v14.0) Test error 📹 Watch
✅ Passed Tests (1)
Test Platform Device Duration Team Recording
Perps add funds Android Google Pixel 8 Pro (v14.0) 8.79s @mm-perps-engineering-team 📹 Watch

Branch: fix/oversubscription-perps-top-movers · Build: Normal · Commit: 68b37c6 · View full run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant