Commit 4a528d0
authored
perf(perps): improved navigation time on low/middle range android devices (MetaMask#22701)
## **Description**
This PR improves navigation performance in the Perps feature to provide
a smoother, more responsive experience on lower-end Android devices.
**Problem:**
Navigation between Perps screens can feel sluggish on lower-end devices,
particularly when:
- Tapping market cards to view market details
- Opening order screens via Long/Short buttons
- Transitions lack visual feedback and feel unresponsive
**Solution:**
Implemented two targeted optimizations:
1. **Navigation Animations** - Enable smooth screen transitions with
proper animation timing to provide visual feedback during navigation
2. **Memoize Market Lookups** - Pre-compute market data lookups in
PerpsCard (200-300 items) to eliminate blocking array searches during
user interactions
**Impact:**
- Smoother navigation transitions with visual feedback
- Eliminated blocking array searches during user taps (200-300 item
lookups)
- Improved perceived performance on lower-end devices
## **Changelog**
CHANGELOG entry: Improved Perps navigation performance for smoother
screen transitions on lower-end devices
## **Related issues**
Fixes: [Internal investigation - no public issue]
## **Manual testing steps**
```gherkin
Feature: Perps Navigation Performance
Scenario: user navigates from home to market details
Given user is on Perps home screen with market cards visible
When user taps on any market card (e.g., BTC-USD)
Then screen transition should feel smooth and immediate
And market details view should appear without noticeable delay
Scenario: user opens order screen from market details
Given user is viewing market details for any asset
When user taps the "Long" or "Short" button
Then order screen should appear with smooth animation
And screen should load without noticeable delay
Scenario: user navigates between multiple markets quickly
Given user is on Perps home screen
When user taps multiple different market cards in quick succession
Then each navigation should feel responsive
And there should be no UI freezing between taps
Scenario: user tests on lower-end Android device
Given user has a mid-to-low-end Android device (e.g., 4GB RAM)
When user performs all navigation flows in Perps
Then navigation should feel snappy with smooth animations
And tapping market cards should respond immediately without lag
```
## **Screenshots/Recordings**
### **Before**
<!-- Add before recordings when testing on device -->
### **After**
<!-- Add after recordings when testing on device -->
## **Technical Details**
### Navigation Animations
**File:** `app/components/UI/Perps/routes/index.tsx`
- Enable navigation animations for smooth screen transitions
- Provides visual feedback during navigation
### Memoized Market Lookups
**File:** `app/components/UI/Perps/components/PerpsCard/PerpsCard.tsx`
- Added `useMemo` to pre-compute market lookups:
```typescript
const market = useMemo(
() => markets.find((m) => m.symbol === symbol),
[markets, symbol],
);
```
- Eliminates blocking array search during user taps (markets array
typically contains 200-300 items)
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable (performance improvements -
visual testing required)
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
## **Testing Notes for Reviewers**
**Focus Areas:**
1. Test on lower-end Android device (4GB RAM or less) if possible
2. Pay attention to navigation "feel" - should be immediate and smooth
with animated transitions
3. Test rapid tapping of market cards - should remain responsive
4. No regression in functionality - all data should still load correctly
**What to look for:**
- ✅ Smooth animated transitions between screens
- ✅ Instant response when tapping market cards or Long/Short buttons
- ✅ No lag when tapping cards in quick succession
- ❌ No frozen transitions or unresponsive UI
- ❌ No missing data or broken functionality
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Defers non-critical PerpsOrderView data subscriptions until after
first render, memoizes PerpsCard market lookup, enables default screen
animations, and updates tests to await deferred data.
>
> - **PerpsOrderView (`PerpsOrderView.tsx`)**:
> - *Deferred data loading*: Introduces `isDataReady` (via
`requestAnimationFrame`) to delay `usePerpsMarketData`,
`usePerpsLivePrices`, and `usePerpsTopOfBook` subscriptions until after
initial render; updates `usePerpsMeasurement` conditions accordingly.
> - Minor refactors: computed styles memoization unchanged behavior;
validation/messages and handlers unchanged but aligned with deferred
data.
> - **PerpsCard (`PerpsCard.tsx`)**:
> - *Performance*: Adds `useMemo` for market lookup and simplifies
`handlePress` deps to use memoized `market`.
> - **Navigation (`routes/index.tsx`)**:
> - Removes `animationEnabled: false` to allow default transitions.
> - **Tests (`PerpsOrderView.test.tsx`)**:
> - Mocks `usePerpsLivePrices`; switches to async assertions
(`findByText`) for values shown after deferred readiness.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
faffdca. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4b55670 commit 4a528d0
4 files changed
Lines changed: 53 additions & 35 deletions
File tree
- app/components/UI/Perps
- Views/PerpsOrderView
- components/PerpsCard
- routes
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
| |||
1244 | 1248 | | |
1245 | 1249 | | |
1246 | 1250 | | |
1247 | | - | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
1248 | 1254 | | |
1249 | 1255 | | |
1250 | 1256 | | |
| |||
2839 | 2845 | | |
2840 | 2846 | | |
2841 | 2847 | | |
2842 | | - | |
| 2848 | + | |
2843 | 2849 | | |
2844 | 2850 | | |
2845 | 2851 | | |
| |||
2849 | 2855 | | |
2850 | 2856 | | |
2851 | 2857 | | |
2852 | | - | |
| 2858 | + | |
2853 | 2859 | | |
2854 | 2860 | | |
2855 | 2861 | | |
| |||
2860 | 2866 | | |
2861 | 2867 | | |
2862 | 2868 | | |
2863 | | - | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
2864 | 2872 | | |
2865 | 2873 | | |
2866 | 2874 | | |
Lines changed: 17 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
163 | 172 | | |
164 | 173 | | |
165 | 174 | | |
| |||
216 | 225 | | |
217 | 226 | | |
218 | 227 | | |
219 | | - | |
| 228 | + | |
220 | 229 | | |
221 | | - | |
| 230 | + | |
222 | 231 | | |
223 | 232 | | |
224 | 233 | | |
| |||
274 | 283 | | |
275 | 284 | | |
276 | 285 | | |
277 | | - | |
| 286 | + | |
278 | 287 | | |
279 | 288 | | |
280 | | - | |
| 289 | + | |
281 | 290 | | |
282 | 291 | | |
283 | 292 | | |
284 | 293 | | |
285 | | - | |
| 294 | + | |
286 | 295 | | |
287 | | - | |
| 296 | + | |
288 | 297 | | |
289 | 298 | | |
290 | | - | |
| 299 | + | |
291 | 300 | | |
292 | 301 | | |
293 | | - | |
| 302 | + | |
294 | 303 | | |
295 | 304 | | |
296 | 305 | | |
| |||
Lines changed: 24 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
104 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | 129 | | |
131 | 130 | | |
132 | 131 | | |
| |||
0 commit comments