Smooth scrolling and instant press feedback depend on the app producing a new frame on time, over and over. iOS and Android devices display at least 60 frames per second, which gives your code and the UI system at most 16.67 ms to build each frame. When a screen feels sluggish, the first thing to find out is which thread missed that deadline, and the Perf Monitor answers that during development.

Key terms

  • Dropped frame: a frame whose work did not finish within its time slot, which makes the UI appear unresponsive.
  • Perf Monitor: the in-app performance overlay you toggle from the Dev Menu in a development build.
  • JS frame rate: the frame rate of the JavaScript thread.
  • UI frame rate: the frame rate of the main thread.
  • Release build: the production build of the app, where the Dev Menu, LogBox and React Native DevTools are disabled.

Counting frames against the clock

At 60 frames per second, each frame gets a slot of 1000 / 60 ms, about 16.67 ms. If the work for a frame doesn't fit in its slot, the frame is dropped and the UI looks unresponsive for that interval.

Dropped frames add up quickly. Suppose a new state on the root component re-renders some computationally expensive subtrees and the update takes 200 ms. Divide the busy time by the slot length and round to the nearest whole frame: 200 / 16.67 gives 12 dropped frames in a row, and any animation controlled by JavaScript appears to freeze for that time.

In a native trace, frame boundaries fall about every 16 ms. All the UI work for a frame has to finish before its period ends, and an app where no thread is working near a frame boundary renders at 60 FPS.

Turning on the Perf Monitor

Open the Dev Menu and select Perf Monitor. On both iOS and Android the item is labeled "Show Perf Monitor" while the overlay is hidden and "Hide Perf Monitor" while it's visible, so the same entry turns it off again.

The overlay only exists in development builds. The Dev Menu is disabled in release builds, and the Perf Monitor is one of its items.

Reading JS and UI on each platform

There are two frame rates to watch, the JS frame rate for the JavaScript thread and the UI frame rate for the main thread, and what the overlay shows of them depends on the platform.

On iOS you get two graphs, labeled JS and UI. The UI graph is driven by a display link on the main run loop. The JS graph's display link is scheduled on the JavaScript thread, and a JavaScript thread that is unresponsive for a frame counts as a dropped frame. A JS graph that collapses while UI stays near 60 tells you the JavaScript thread is busy while the main thread keeps drawing on time.

On Android the overlay is a few lines of text: the UI frame rate, the frames dropped so far, and a stutter count, where a stutter is 4 or more frames dropped in a row between two drawn frames. The frame rate is also written to logcat while the overlay is on. The Android overlay shows no JS frame rate in a default app, so if you follow the performance guide on Android and look for a second rate, you won't find one. To check the JavaScript thread on Android, use a native trace instead.

Treat these numbers as a guide. The Perf Monitor runs inside the app, and accurate measurements come from the native tooling in Android Studio and Xcode.

Profiling a release build

JavaScript thread performance suffers greatly in dev mode, because the runtime does a lot of extra work to produce warnings and error messages, so test performance in release builds.

The commands in the release build example run each platform in release mode from the project root. On Android, --mode="release" only works once release signing is set up. On iOS, a build for the Release scheme disables the in-app Dev Menu and bundles the JavaScript locally. To get the same configuration from Xcode, open Product > Scheme > Edit Scheme, select the Run tab and set the Build Configuration dropdown to Release.

A release build has no Dev Menu, so it has no Perf Monitor either. Profile it with native tools, with Development Mode turned off: Instruments on iOS and the Android Studio Profiler on Android. The standalone systrace tool was removed from Android platform-tools, and the Android Studio Profiler replaces it.

In a trace, check which thread's work crosses the frame boundaries. When the JS thread executes almost all the time and across boundaries, the problem lies in JavaScript. When the UI and render threads are the ones with work crossing boundaries, the problem lies in the native views being rendered.

Code Examples

bash
# Android: works once release signing is set up
npm run android -- --mode="release"

# iOS: the Release build disables the Dev Menu and bundles the JavaScript locally
npm run ios -- --mode="Release"
✓ Completed