WhoBuilt

React Native Performance - Take 2

Oct 21, 2020· 25 min· 1.2K views·Watch on YouTube

Speaker

Parashuram N of Callstack speaks about measuring and improving React Native performance at React Native EU 2020.

From startup time to frame rates

Parashuram revisits his 2019 talk, which focused on application startup and native-side optimizations such as TurboReactPackage and Hermes. For this second take, he shifts attention toward JavaScript performance and frame rates, aiming to improve responsiveness and smoothness.

Measure JavaScript work

React Native’s performance monitor reports UI and JavaScript FPS, based on frame callbacks and whether JavaScript work or bridge batches are processed. Parashuram explains sampling profiles as a way to inspect JavaScript call stacks over time. On Android, Hermes profiles can be captured and converted with `react-native profile-hermes` for viewing in Chrome; iOS profiles can be recorded through Safari.

Find costly React updates

The React Profiler in Flipper shows React commits, component work, and which props or state caused an update. Parashuram suggests using that information to limit unnecessary renders, including with `shouldComponentUpdate`. Flipper also provides tools for inspecting images, network activity, and native layout.

Keep interactions and animations responsive

Long JavaScript event handlers can delay later touches even while the UI thread continues to scroll. Parashuram recommends giving immediate feedback first, then scheduling longer work with `InteractionManager.runAfterInteractions` or timers, while breaking up tasks that run too long. For smoother animations, `useNativeDriver` and `LayoutAnimation` move animation work to the UI thread, with tradeoffs in control and selectivity.

Account for UI work and lists

Parashuram notes that short timer intervals can contribute to problems because timers call through native modules and the bridge. Image scaling and overlapping translucent views can also burden the UI thread; rasterizing frequently resized images may help. He closes by pointing to scrolling lists as a separate challenge involving both memory use and the amount of data rendered.

Takeaways

  • Profile a slow workflow to find which JavaScript functions consume time before optimizing.
  • Use React Profiler commit data to identify updates triggered by props or state.
  • Return quick visual feedback from touch handlers, then schedule and split longer work.
  • Move suitable animations to the UI thread to reduce jank from busy JavaScript.
  • Render only relevant list data to limit memory use and unnecessary computation.

Mentioned in this talk

Search inside this talk

What was claimed 8

  • feature
    Parashuram N: Gave a talk on React Native performance
    “I'm here to talk to you about React Native Performance.”
    YouTube
    Unverified1 source· Talk
  • feature
    Hermes Agent: JavaScript engine for running JavaScript in a React Native application
    “Facebook announced Hermes, the JavaScript engine for running JavaScript in a React Native application.”
    YouTube
    Unverified1 source· Talk
  • feature
    Hermes Agent: Provides a sampling profiler on Android
    “if you're using Hermes, you can open the debug menu and select “Enable Sampling Profiler.””
    YouTube
    Unverified1 source· Talk
  • feature
    Flipper: Includes a React Profiler for viewing commits and render costs
    “You can use it to show the React Profiler.”
    YouTube
    Unverified1 source· Talk
  • feature
    Flipper: Includes image viewing, a network inspector, and multiple plugins
    “Flipper also has some really amazing tools, including a way to view images ... a network inspector”
    YouTube
    Unverified1 source· Talk
  • feature
    InteractionManager: Schedules work after interactions complete
    “you can call InteractionManager.runAfterInteractions to run something after the interactions have completed.”
    YouTube
    Unverified1 source· Talk
  • feature
    Native Driver: Moves animation calculations to the UI thread
    “That's how useNativeDriver works.”
    YouTube
    Unverified1 source· Talk
  • feature
    LayoutAnimation: Animates layout changes on the UI thread
    “React Native actually has this hidden gem called LayoutAnimation that lets you animate groups of objects together.”
    YouTube
    Unverified1 source· Talk

Related talks