React Native performance

Learn React Native performance on Android: the JS and UI threads, FlatList tuning, React.memo and useCallback, Reanimated worklets and Perfetto profiling. About 25 minutes.

Why it matters

  • Long lists that re-render every row on each state change cause jank and blank areas on mid-range Android devices; interviewers ask how you would find and fix it.
  • FlatList is not a RecyclerView. Knowing that it virtualizes (mounts a window of rows and unmounts the rest) explains which props matter and when a recycling list such as FlashList helps.
  • Animations driven from JavaScript compete with React work on the JS thread; react-native-reanimated worklets and the native driver run them on the UI thread, a standard senior interview answer.
  • Profiling with React Native DevTools and Perfetto tells you whether the JS thread or the UI thread is the bottleneck, so you fix the right thing.

The simple explanation

  • Think of the JS thread as a kitchen and the UI thread as the dining room.
  • The kitchen (JS thread, Hermes) prepares dishes: event handlers, state updates, React renders.
  • The dining room (UI thread) serves them: it mounts and draws native Android views and handles native scrolling.
  • If the kitchen is busy, the dining room keeps serving what it has, but nothing new arrives: taps feel ignored and fast scrolling shows empty plates (blank areas).
  • FlatList only keeps the tables near the guest set; tables far away are cleared and set again when the guest walks back.
  • Reanimated hires a waiter who adjusts the plates in the dining room directly, without asking the kitchen each time.

How do you make a React Native app fast on Android? Keep the JS thread free, render fewer components, and tune lists and animations. React Native runs your JavaScript on the JS thread (Hermes by default) and draws native views on the UI thread (the Android main thread). When state changes, React re-renders on the JS thread, Fabric commits the new tree (including Yoga layout), and the UI thread mounts the changes. A busy JS thread delays every update.

FlatList is built on VirtualizedList and a ScrollView. It does not wrap a RecyclerView and does not recycle views: it mounts the items inside a window around the viewport and unmounts items that leave it. The main props:

PropDefaultEffect
windowSize21Window size in viewport heights (10 above, 10 below, 1 visible)
maxToRenderPerBatch10Items rendered per batch as you scroll
initialNumToRender10Items rendered on first mount
removeClippedSubviewstrue on Android, false elsewhereDetaches off-screen native views from the view hierarchy

getItemLayout tells FlatList the length and offset of each item, so it does not have to wait for async layout measurements, and scrollToIndex works without measuring.

Re-renders are the other cost. React.memo skips a component when its props are shallow-equal. useCallback and useMemo keep function and object references stable so that shallow compare can succeed.

For animations, Animated with JS-driven values updates on the JS thread. Animated with useNativeDriver: true (for non-layout props such as transform and opacity) and react-native-reanimated worklets run on the UI thread.

Notes

  • The JS thread runs your code and React renders; the UI thread mounts native views and handles native scroll. Heavy JS work (parsing large JSON, rendering many components) delays taps and updates.
  • FlatList virtualizes instead of recycling: rows outside the window are unmounted, and a row coming back is rendered again from scratch. Shopify's FlashList recycles row components, which can help very long or complex lists.
  • windowSize is measured in viewport heights. A smaller value mounts fewer rows and uses less memory but shows more blank areas during fast scrolling.
  • getItemLayout removes async layout measurement for fixed-size rows; its signature is (data, index) => ({ length, offset, index }).
  • removeClippedSubviews is already true by default on Android. It detaches views rather than freeing them, so it saves drawing work more than memory.
  • React.memo does a shallow prop comparison. Passing a new object, array or inline function every render defeats it; stabilize those with useMemo or useCallback.
  • useCallback(fn, []) returns the same function for the component's lifetime, but the callback then sees only the values from the first render. List every value it reads in the dependency array.
  • FlatList only re-renders when its props change. If renderItem reads state that is not in data, pass that state through extraData.
  • Reanimated worklets run on the UI thread, so an animation keeps running smoothly while the JS thread is busy.
  • Judge performance on a release build: debug builds run React in development mode with extra checks. Use React Native DevTools (React Profiler) in development to find extra renders, and a Perfetto trace of a release build to see thread activity.

Code example

A tuned FlatList with a memoized row, a stable renderItem and fixed-height getItemLayout:

import { memo, useCallback } from 'react';
import { FlatList, StyleSheet, Text, View, type ListRenderItem } from 'react-native';
 
type Item = {
  id: string;
  label: string;
};
 
const ROW_HEIGHT = 64;
 
// Memoized row: skips re-render when its props are shallow-equal
const Row = memo(function Row({ label }: { label: string }) {
  return (
    <View style={styles.row}>
      <Text>{label}</Text>
    </View>
  );
});
 
export function Feed({ items }: { items: Item[] }) {
  // Stable reference, so FlatList's props do not change on every parent render
  const renderItem = useCallback<ListRenderItem<Item>>(
    ({ item }) => <Row label={item.label} />,
    []
  );
 
  // Fixed-height rows: FlatList can compute positions without measuring
  const getItemLayout = useCallback(
    (_data: ArrayLike<Item> | null | undefined, index: number) => ({
      length: ROW_HEIGHT,
      offset: ROW_HEIGHT * index,
      index,
    }),
    []
  );
 
  return (
    <FlatList
      data={items}
      keyExtractor={(item) => item.id}
      renderItem={renderItem}
      getItemLayout={getItemLayout}
      windowSize={11}
      initialNumToRender={15}
    />
  );
}
 
const styles = StyleSheet.create({
  row: { height: ROW_HEIGHT, paddingHorizontal: 16, justifyContent: 'center' },
});
  • memo on Row means a parent re-render does not re-render rows whose label did not change.
  • renderItem reads nothing from the component scope, so an empty dependency array is correct. If it used state, that state would go in the dependency array and in extraData.
  • getItemLayout uses the same constant as the row style, so the declared height and the real height cannot drift apart.
  • windowSize={11} mounts about half as many rows as the default 21, trading some blank-area risk for less work and memory. Measure before and after on a real device.

Run the idea in plain Kotlin

data class RowProps(val id: Int, val label: String, val liked: Boolean)

// VirtualizedList-style window: viewports above and below the visible one stay mounted
fun windowRange(firstVisible: Int, perViewport: Int, windowSize: Int, total: Int): IntRange {
  val extra = (windowSize - 1) / 2 * perViewport
  val start = maxOf(0, firstVisible - extra)
  val end = minOf(total - 1, firstVisible + perViewport - 1 + extra)
  return start..end
}

// React.memo-style check: re-render only when props differ (data class equals stands in for shallow compare)
fun rowsRerendered(before: List<RowProps>, after: List<RowProps>, memo: Boolean): Int =
  before.indices.count { i -> !memo || before[i] != after[i] }

fun main() {
  val total = 5000
  val perViewport = 10
  val windowSize = 5

  var mounted = emptySet<Int>()
  var mounts = 0
  var unmounts = 0
  var maxMounted = 0
  for (first in 0 until total step perViewport) {
      val next = windowRange(first, perViewport, windowSize, total).toSet()
      mounts += (next - mounted).size
      unmounts += (mounted - next).size
      mounted = next
      maxMounted = maxOf(maxMounted, mounted.size)
  }
  println("Items in data: " + total)
  println("Most rows mounted at once: " + maxMounted)
  println("Mounts while scrolling to the end: " + mounts)
  println("Unmounts while scrolling to the end: " + unmounts)

  val visible = (0 until 50).map { RowProps(it, "Item " + it, false) }
  val afterLike = visible.map { if (it.id == 3) it.copy(liked = true) else it }
  println("Rows re-rendered after one like, no memo: " + rowsRerendered(visible, afterLike, memo = false))
  println("Rows re-rendered after one like, with memo: " + rowsRerendered(visible, afterLike, memo = true))
}

Expected output:

Items in data: 5000
Most rows mounted at once: 50
Mounts while scrolling to the end: 5000
Unmounts while scrolling to the end: 4970
Rows re-rendered after one like, no memo: 50
Rows re-rendered after one like, with memo: 1
  • Only 50 of 5000 rows are ever mounted at once, but almost every row is mounted on the way down and unmounted again: virtualization bounds memory, it does not reuse rows.

In production

Feed scrolling janks and shows blank rows on mid-range Android
  • Users on mid-range Android phones reported a stuttering feed and white gaps while flinging through it.
  • Tapping "like" on one post froze scrolling briefly; the React Profiler showed every mounted row re-rendering on each like.
  • renderItem was an inline arrow function, rows were not memoized, and each row received a new style object literal on every render.
The fix
  • Wrapped the row in React.memo, moved renderItem into useCallback, and moved row styles into StyleSheet.create so props stayed referentially equal.
  • Passed the liked-post set through extraData and gave each row only its own liked boolean, so one like changed one row's props.
  • Added getItemLayout for the fixed-height rows and tried a smaller windowSize, comparing blank areas and memory on a test device.
  • The profiler then showed a single row re-rendering per like, and a Perfetto trace of a release build showed the JS thread no longer busy for long stretches during scroll.
Scroll-linked header animation stutters
  • A collapsing header was driven by an Animated.Value updated from a JS onScroll handler.
  • While the list loaded more pages, the header lagged behind the finger, because every scroll event had to pass through the busy JS thread.
  • React Native DevTools showed long JS tasks coinciding with the stutter.
The fix
  • Replaced the JS handler with Reanimated: useAnimatedScrollHandler writes the offset to a shared value, and useAnimatedStyle with interpolate computes the header's transform.
  • Both run as worklets on the UI thread, so the header follows the scroll even while the JS thread renders new rows.
  • For a simpler case (only transform or opacity), Animated.event with useNativeDriver: true would also have moved the work off the JS thread.

Common mistakes

  • Using the array index as the key. When items are inserted, removed or reordered, React matches rows by key, so state and memoized output stick to the wrong item. Use a stable id from the data.
  • Creating new objects or functions in render and passing them to memoized rows. A new style object or inline callback each render makes the shallow compare fail. Hoist styles into StyleSheet.create and stabilize callbacks with useCallback.
  • Stale values in useCallback with empty deps. An empty dependency array freezes the values from the first render. List what the callback reads, and pass changing state to FlatList through extraData.
  • Driving scroll-linked animations from JS. A JS onScroll handler updating an animation competes with rendering. Use Reanimated worklets or Animated.event with useNativeDriver: true.
  • Judging performance in a debug build. Development mode adds checks and warnings that slow React down. Find extra renders with the profiler in development, but measure frame drops on a release build.
  • Treating FlatList like a RecyclerView. It unmounts and remounts rows instead of recycling them, so expensive row mount work (large images, heavy layouts) hurts on every scroll. Keep rows light, or try FlashList for long complex lists.

Interview questions

Answer out loud first. Then reveal the answer and compare it at each depth.

“What triggers a re-render in React Native and how do you prevent unnecessary ones?”

“How does FlatList work and which props matter for performance?”

“Why use react-native-reanimated instead of JS-driven Animated values?”

“How do you profile a slow React Native screen on Android?”

Quiz

How does FlatList handle items that scroll far outside the viewport?

What does getItemLayout give FlatList?

Which thread do Reanimated worklets run animations on?

Why wrap a FlatList row component in React.memo?

0 of 4 answered

Mini task

Tune a FlatList in your React Native project (15 min)

  1. Open a list screen, or create a FlatList with 5000 dummy items: Array.from({ length: 5000 }, (_, i) => ({ id: String(i), label: 'Item ' + i })).
  2. Add a "like" button to each row backed by state in the parent. Record with the React Profiler in React Native DevTools while tapping it and note how many rows re-render.
  3. Give the row a fixed height from a constant and add getItemLayout that returns { length: ROW_HEIGHT, offset: ROW_HEIGHT * index, index }.
  4. Wrap the row in React.memo, move renderItem into useCallback, pass each row only its own liked boolean, and pass the liked set through extraData.
  5. Record again and confirm that one tap re-renders one row.
  6. Run a release build (npm run android -- --mode="release"), fling the list and record a Perfetto trace. Check that the JS thread is not busy for long stretches during scroll.

Done when: one like re-renders one row in the profiler, the list scrolls without visible stutter on a mid-range device in a release build, and you can point to the JS and UI threads in your Perfetto trace.