Mobile Performance Optimisation

One frame gets 16.67 ms; the JS thread runs React and logic, the UI thread scrolls and runs Reanimated worklets. Measure first, in a release build: React…

Mrs. Rini's cashier tablet is starting to feel heavy: buttons answer late when tapped, and the History list stutters as it scrolls. Keeping an app answering touches and scrolling without stutter is what performance optimisation is about. A phone draws at least 60 frames per second, so every frame gets at most 16.67 ms. When the work runs past that, a frame is dropped and the screen feels choppy (jank). At Mrs. Rini's counter, one cashier (the JavaScript thread) serves every request, while the clothes conveyor (the UI thread) keeps moving on its own. When the cashier is busy adding up 5,000 receipts, customers who want to pay wait, even though the conveyor keeps running.

Measure first, then change

Tool What for How to open it
React Native DevTools, React Profiler tab which components render and for how long press j in the npx expo start terminal
React Native DevTools, Performance panel a recording of JavaScript execution a panel new since React Native 0.83 (SDK 57 uses 0.86)
Performance monitor UI thread and JS thread FPS, right on the phone developer menu, "Toggle performance monitor"
Android Studio Profiler, Xcode Instruments CPU, memory and system traces on the native side from Android Studio and Xcode

Two threads, one frame

The JavaScript thread runs React, state and requests. The UI thread draws native views and scrolls a ScrollView. The performance monitor shows two FPS numbers, one per thread.

Long lists: FlatList

ScrollView + map makes every row at once. FlatList only makes the rows around the screen (virtualisation). Its defaults, checked in React Native 0.86's code:

Prop Default Meaning
initialNumToRender 10 rows made in the first render
maxToRenderPerBatch 10 extra rows per turn
windowSize 21 the window = 21 times the screen height: the visible screen plus up to 10 screens above and 10 below
removeClippedSubviews true on Android, false on iOS detach views that left the screen from the native hierarchy

Guess first: the History screen holds a year's 5,000 receipts, each row 72 tall, the list area 640 tall. How many OrderRows does ScrollView + map make, and how many does FlatList make with the defaults above?

For 5,000 receipts, rows of 72, an area of 640: ScrollView makes 5,000 OrderRows before the first screen shows. FlatList makes 10 in the first render, then adds 10 at a time until its window is full. At the very top, the window is 640 + 10 × 640 = 7,040, so about 98 rows, and that number doesn't grow even with 50,000 receipts.

// src/app/history.tsx (cashier mode)
const ROW_HEIGHT = 72; // OrderRow: height 72

export function History({ receipts }: { receipts: Order[] }) {
  const open = useCallback((id: string) => router.push(`/order/${id}`), []);

  return (
    <FlatList
      data={receipts}
      keyExtractor={(o) => o.id}
      renderItem={({ item }) => <OrderRow order={item} onPress={open} />}
      getItemLayout={(_, index) => ({ length: ROW_HEIGHT, offset: ROW_HEIGHT * index, index })}
      windowSize={11}
    />
  );
}

Re-renders: memo and React Compiler

When #13 changes to "Ready for pickup", TanStack Query hands out a new array, but the other order objects stay the same objects (structural sharing). Who re-renders depends on two things. First, every FlatList row is wrapped in a cell that is a PureComponent: if its item and renderItem are the same, that cell is skipped. Second, memo(OrderRow) skips a render when all props are equal by Object.is. Counted for the 98 mounted rows, without React Compiler:

renderItem OrderRow What re-renders
a new function every render no memo 98 rows
a new function every render memo, but onPress={() => open(item.id)} 98 rows: its props always differ
a new function every render memo, onPress={open} from useCallback 1 row: #13
stable (useCallback) anything 1 row: the other cells are skipped

FlashList

@shopify/flash-list reuses the views of rows that left the screen instead of throwing them away. npx expo install on SDK 57 installs 2.0.2 (npm already has 2.3.3). Version 2 only runs on the New Architecture, is pure JavaScript (no native code), and no longer needs estimatedItemSize:

import { FlashList } from '@shopify/flash-list';

<FlashList data={receipts} keyExtractor={(o) => o.id} renderItem={({ item }) => <OrderRow order={item} onPress={open} />} />

Because views are reused, images in a row need recyclingKey (see below), so the previous customer's photo doesn't flash for a moment.

Images and app start time

⚠️ Why is it still slow after optimising?

TL;DR: One frame gets 16.67 ms; the JS thread runs React and logic, the UI thread scrolls and runs Reanimated worklets. Measure first, in a release build: React Native DevTools (React Profiler, the Performance panel since 0.83), "Toggle performance monitor", and Android Studio Profiler and Xcode Instruments; Flipper and Systrace are left behind. The most common cause of jank is excessive re-rendering: a stable renderItem, or memo with stable props (useCallback), means only the #13 row re-renders instead of 98, and React Compiler in SDK 57 memoizes a lot automatically. For 5,000 receipts, ScrollView makes 5,000 rows, FlatList 10 then about 98 (defaults initialNumToRender 10, maxToRenderPerBatch 10, windowSize 21); getItemLayout makes scrollToIndex jumps work, keyExtractor gives stable keys. FlashList 2 (2.0.2 on SDK 57) reuses views, needs the New Architecture, and has no estimatedItemSize. Use expo-image with cachePolicy and recyclingKey, check the bundle (2.7 MB, 1,243 modules in this project) with Expo Atlas, and keep heavy work out of the root layout.

⚡ A 16.67 ms budget

Meaning: A phone draws at least 60 frames per second, so every frame gets at most 16.67 ms. When the work runs past that, a frame is dropped and the screen feels choppy (jank). Measure first in a release build with React Native DevTools and the performance monitor, then change things.

⚡ 5,000 receipts in one list

Guess first: the History screen holds 5,000 receipts, each row 72 tall, the list area 640 tall. How many OrderRows does ScrollView + map make, and how many does FlatList make?

ScrollView makes all 5,000 at once. FlatList makes 10 in the first render, then adds more until its window is full: about 98 at the very top.

Meaning: FlatList only makes the rows around the screen. That 98 doesn't grow, even with 50,000 receipts.

⚡ Excessive re-rendering

Write:

const open = useCallback((id: string) => router.push(`/order/${id}`), []);
<OrderRow order={item} onPress={open} />

Meaning: The most common cause of jank is excessive re-rendering. With memo(OrderRow) and a stable onPress from useCallback, only the #13 row re-renders when #13 changes, not 98. React Compiler in SDK 57 memoizes a lot automatically.

What you will learn