7 Ways to Make Your React Native App Blazing Fast

Amir Hosseini
5 min readNov 3, 2023

--

If you’re a React Native developer, you’ve probably experienced a laggy app at some point. This can be frustrating for users and can lead to bad reviews.

But don’t worry, there are a few things you can do to improve the performance of your React Native app.
In this article, we’ll discuss some of the most effective ways to speed up your React Native app. We’ll also provide some example code to help you get started.

1. Use the latest version of React Native
The React Native team is constantly releasing new versions of the framework with performance improvements and bug fixes. It’s important to keep your React Native app up to date to take advantage of these improvements.
To check your React Native version, run the following command in your terminal:

react-native --version

If you’re not on the latest version, you can update your React Native project by running the following command:

react-native upgrade

2. Use the Hermes JavaScript engine
Hermes is a new JavaScript engine that is optimized for React Native. It can significantly improve the startup time and performance of React Native apps.
To use Hermes, simply add the hermes dependency to your React Native project:

npm install hermes-engine

Once you’ve added the Hermes dependency, you need to enable it in your React Native project’s metro.config.js file:

3. Use React.memo() and PureComponent
React.memo() and PureComponent are two React features that can help to improve performance by preventing unnecessary re-renders.
React.memo() can be used to memoize functional components, while PureComponent can be used to memoize class components.
To use React.memo(), simply wrap your functional component in the React.memo() function. For example:

To use PureComponent, simply extend your class component from the PureComponent class. For example:

4. Use FlatList and SectionList instead of ScrollView

FlatList and SectionList are two React Native components that are optimized for rendering large lists. They can significantly improve the performance of scrolling and rendering lists.
To use FlatList or SectionList, simply replace your ScrollView component with a FlatList or SectionList component. For example:

5. Cache images
Images can take a long time to load, which can cause your React Native app to lag. You can improve performance by caching images so that they do not have to be loaded every time they are displayed.
There are a number of different libraries that you can use to cache images in React Native. One popular library is React Native Fast Image.
To use React Native Fast Image, simply wrap your image components in the FastImage component. For example:

6. Use code splitting and lazy loading
Code splitting and lazy loading can help to reduce the size of your React Native app and improve startup time. Code splitting allows you to split your JavaScript code into separate bundles, which can be loaded on demand. Lazy loading allows you to load modules only when they are needed, which can reduce the initial load time of your app.

7. Profile your app

Profiling your app is the process of collecting data about how your app is performing. This data can help you to identify performance bottlenecks and make necessary optimizations.
There are a number of different tools available for profiling React Native apps. One popular tool is the React Native Profiler. The React Native Profiler can be used to profile the performance of the JavaScript thread and the main thread side-by-side.
To profile your app using the React Native Profiler, simply follow these steps:

  1. Open the Dev Menu by pressing d.
  2. Select Perf Monitor.
  3. Select the type of performance data that you want to collect.
  4. Start profiling by pressing the Record button.
  5. Perform the actions that you want to profile.
  6. Stop profiling by pressing the Stop button.

Once you have stopped profiling, the React Native Profiler will display a flame graph of the performance data. The flame graph will show you which functions are taking the most time to execute.
Another popular tool for profiling React Native apps is the Chrome Performance Profiler. The Chrome Performance Profiler can be used to profile the performance of your app’s JavaScript code.
To profile your app using the Chrome Performance Profiler, follow these steps:

  1. Connect your device to your computer.
  2. Open Chrome and navigate to chrome://inspect.
  3. Select your device from the list of devices.
  4. Click the Open DevTools button.
  5. Click the Performance tab.
  6. Start profiling by clicking the Record button.
  7. Perform the actions that you want to profile.
  8. Stop profiling by clicking the Stop button.

Once you have stopped profiling, the Chrome Performance Profiler will display a timeline of the performance data. The timeline will show you when and where your app’s JavaScript code is spending the most time.
By profiling your app, you can identify performance bottlenecks and make necessary optimizations. This can lead to a faster and more responsive app for your users.
Here are some additional tips for profiling your React Native app:

  • Profile your app on a real device instead of a simulator. Simulators can provide inaccurate performance results.
  • Profile your app under different load conditions. For example, profile your app when it is idle, when it is under moderate load, and when it is under heavy load.
  • Profile your app on different devices. For example, profile your app on a high-end device and a low-end device.
  • Use the performance data that you collect to identify performance bottlenecks and make necessary optimizations.

Conclusion
By following the tips in this article, you can significantly improve the performance of your React Native apps. Remember to keep your React Native app up to date, use the Hermes JavaScript engine, use React.memo() and PureComponent, use FlatList and SectionList instead of ScrollView, cache images, use code splitting and lazy loading, and profile your app.

--

--