Reputation:
Is there a good way to know our react-native app is working well?
although I know there is a perf monitor
When I enable Perf Monitor
, here is some options which I dont know what do they mean.
150 dropped so far
like: 12 stutters (4+) so far
and finally what is fps
it self in react-native?
Upvotes: 7
Views: 3219
Reputation: 1410
FPS means "Frame per Second". A "smooth" app should run at 60fps, most of the time. Most phones nowadays have 60hz displays (meaning they only refresh 60 times per second), and thus only high-end phones will be able to display more than 60 frames in a second. There's a few things you can do to ensure your RN app is running at optimal speed.
As you may already know crossing the "bridge" (Javascript -> Native) is slow, and causes stuttering / low FPS. There's a lot of material out there explaining how this bridge works in detail, so I won't talk much about it. Try to minimise the amount of work being done (specially bridge crosses) during screen transitions or animations. You can do this by using the InteractionManager
API. Read more about it here.
Don't forget to read the official documentation on Performance.
If you're noticing lag right after opening a new screen, try deferring the rendering until the screen has fully transitioned into the viewport. An example of how to do this:
import { View, InteractionManager } from 'react-native';
class Example extends Component {
constructor(props) {
super(props);
this.state = { ready: false };
}
componentDidMount() {
// After all interactions have been finished we swich the "ready" state variable to true, and only then your component will be rendered.
InteractionManager.runAfterInteractions(() => {
this.setState({ ready: true });
})
}
render() {
if (!this.state.ready) {
return;
}
// Render only when this.state.ready is true (after all interactions have been finalised);
return (
<View></View>
);
}
}
Upvotes: 5