An attempt to have a lighthouse for React Native. Flipper plugin to show a graph of the React Native performance monitor
TypeScript
599
113 commits
updated Nov 7, 2023

Here's a detailed article to go further
This is how the score is calculated below, quite naively, but open to suggestions:

Note that:
Search for rn-perf-monitor in the list of plugins.
Install the plugin
yarn add --dev react-native-flipper-performance-plugin
Then go to iOS/Android section below to continue the install
cd ios && pod installThen depending on your RN version:
./ios/yourapp/AppDelegate.mm (where yourapp depends on your app), add those 8 lines below:(You can check how it's done in the example folder)
// Add those 4 lines before @implementation AppDelegate
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperPerformancePlugin.h>
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// And those 4 lines before RCTAppSetupPrepareApp
#ifdef FB_SONARKIT_ENABLED
FlipperClient *client = [FlipperClient sharedClient];
[client addPlugin:[FlipperPerformancePlugin new]];
#endif
RCTAppSetupPrepareApp(application);
./ios/yourapp/AppDelegate.m (where yourapp depends on your app), add 2 lines:#ifdef FB_SONARKIT_ENABLED
...
// Add this line
#import <FlipperPerformancePlugin.h>
static void InitializeFlipper(UIApplication *application) {
...
// Add this line
[client addPlugin:[FlipperPerformancePlugin new]];
[client start];
}
#endif
In ./android/app/src/debug/java/com/yourapp/ReactNativeFlipper.java (where com/yourapp depends on your app), add:
import tech.bam.rnperformance.flipper.RNPerfMonitorPlugin;
...
client.addPlugin(new RNPerfMonitorPlugin(reactInstanceManager));
You might have previously installed flipper-plugin-rn-performance-android. This is now deprecated, as react-native-flipper-performance-plugin has autolinking and cross-platform support.
You also need to run these steps:
Uninstall the package:
yarn remove flipper-plugin-rn-performance-android
Then remove those lines in ./android/settings.gradle:
include ':flipper-plugin-rn-performance-android'
project(':flipper-plugin-rn-performance-android').projectDir = new File(rootProject.projectDir, '../node_modules/flipper-plugin-rn-performance-android')
and in ./android/app/build.gradle:
debugImplementation project(':flipper-plugin-rn-performance-android')
This plugin does not work with Expo Go, since it adds native code. You can use an Expo custom-dev-client instead.
Install the Expo Flipper plugin. Documentation can be found here: Expo Community Flipper. Install the module along with react-native-flipper:
TL;DR: yarn add -D expo-community-flipper react-native-flipper
Add expo-community-flipper configuration to the plugins section of your app.json. Please check Expo Community Flipper documentation if you need further settings.
Add the plugin to this library AFTER expo-community-flipper
{
"expo": {
"..."
"plugins": [
["expo-community-flipper"], // first
["react-native-flipper-performance-plugin"] // add this after
]
}
}
Make sure to run expo prebuild or expo prebuild --clean afterwards. If the plugin is not recognized on iOS, make sure you call npx pod-install or cd ios && pod install in the root directory of your project.
This library helps you to calculate a Lighthouse score similar to PageSpeed Insights. However, the tool is of no use to you if you cannot draw any optimizations from it. That is why it is recommended to use the plugin together with React DevTools.
The easiest way to use React DevTools is to install it as follows:
yarn add -D react-devtools-core
Then edit your App.tsx/App.js with following default settings.
import { connectToDevTools } from "react-devtools-core";
if (__DEV__) {
connectToDevTools({
host: "localhost",
port: 8097,
});
}
With DevTools you can easily determine why your app is taking too much time for a particular task, most importantly you can find out if you are re-rendering too often. Especially with lists, this can quickly become a knitting trap. Optimize your code and measure the FPS afterwards to get a decent score.
react-native-performance folder in ~/.flipper/config.json as shown on the flipper docsyarn watch inside flipper-desktop825 followers · starred Mar 2022
1,206 followers · starred Jan 2023
166 followers · starred Jun 2022
290 followers · starred Apr 2022
An attempt to have a lighthouse for React Native. Flipper plugin to show a graph of the React Native performance monitor
TypeScript
599
113 commits
updated Nov 7, 2023

Here's a detailed article to go further
This is how the score is calculated below, quite naively, but open to suggestions:

Note that:
Search for rn-perf-monitor in the list of plugins.
Install the plugin
yarn add --dev react-native-flipper-performance-plugin
Then go to iOS/Android section below to continue the install
cd ios && pod installThen depending on your RN version:
./ios/yourapp/AppDelegate.mm (where yourapp depends on your app), add those 8 lines below:(You can check how it's done in the example folder)
// Add those 4 lines before @implementation AppDelegate
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperPerformancePlugin.h>
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// And those 4 lines before RCTAppSetupPrepareApp
#ifdef FB_SONARKIT_ENABLED
FlipperClient *client = [FlipperClient sharedClient];
[client addPlugin:[FlipperPerformancePlugin new]];
#endif
RCTAppSetupPrepareApp(application);
./ios/yourapp/AppDelegate.m (where yourapp depends on your app), add 2 lines:#ifdef FB_SONARKIT_ENABLED
...
// Add this line
#import <FlipperPerformancePlugin.h>
static void InitializeFlipper(UIApplication *application) {
...
// Add this line
[client addPlugin:[FlipperPerformancePlugin new]];
[client start];
}
#endif
In ./android/app/src/debug/java/com/yourapp/ReactNativeFlipper.java (where com/yourapp depends on your app), add:
import tech.bam.rnperformance.flipper.RNPerfMonitorPlugin;
...
client.addPlugin(new RNPerfMonitorPlugin(reactInstanceManager));
You might have previously installed flipper-plugin-rn-performance-android. This is now deprecated, as react-native-flipper-performance-plugin has autolinking and cross-platform support.
You also need to run these steps:
Uninstall the package:
yarn remove flipper-plugin-rn-performance-android
Then remove those lines in ./android/settings.gradle:
include ':flipper-plugin-rn-performance-android'
project(':flipper-plugin-rn-performance-android').projectDir = new File(rootProject.projectDir, '../node_modules/flipper-plugin-rn-performance-android')
and in ./android/app/build.gradle:
debugImplementation project(':flipper-plugin-rn-performance-android')
This plugin does not work with Expo Go, since it adds native code. You can use an Expo custom-dev-client instead.
Install the Expo Flipper plugin. Documentation can be found here: Expo Community Flipper. Install the module along with react-native-flipper:
TL;DR: yarn add -D expo-community-flipper react-native-flipper
Add expo-community-flipper configuration to the plugins section of your app.json. Please check Expo Community Flipper documentation if you need further settings.
Add the plugin to this library AFTER expo-community-flipper
{
"expo": {
"..."
"plugins": [
["expo-community-flipper"], // first
["react-native-flipper-performance-plugin"] // add this after
]
}
}
Make sure to run expo prebuild or expo prebuild --clean afterwards. If the plugin is not recognized on iOS, make sure you call npx pod-install or cd ios && pod install in the root directory of your project.
This library helps you to calculate a Lighthouse score similar to PageSpeed Insights. However, the tool is of no use to you if you cannot draw any optimizations from it. That is why it is recommended to use the plugin together with React DevTools.
The easiest way to use React DevTools is to install it as follows:
yarn add -D react-devtools-core
Then edit your App.tsx/App.js with following default settings.
import { connectToDevTools } from "react-devtools-core";
if (__DEV__) {
connectToDevTools({
host: "localhost",
port: 8097,
});
}
With DevTools you can easily determine why your app is taking too much time for a particular task, most importantly you can find out if you are re-rendering too often. Especially with lists, this can quickly become a knitting trap. Optimize your code and measure the FPS afterwards to get a decent score.
react-native-performance folder in ~/.flipper/config.json as shown on the flipper docsyarn watch inside flipper-desktop825 followers · starred Mar 2022
1,206 followers · starred Jan 2023
166 followers · starred Jun 2022
290 followers · starred Apr 2022