Hi, everyone. Super excited to be talking to you at React Summit. I'm Alex. I'm a tech lead at BAM. We develop mobile apps in Kotlin, Flutter, and of course, React Native, and I just love the subject of mobile apps' performance, so let's dive in.
What does it mean for a mobile app to have good performance? Well, according to this video from Google, which will be available in slides, your apps should be able to run at 60fps, 60 frames per second. This means that your app should be able to draw 60 images per second when you scroll down, for example, to give an impression of smoothness to the user. It's basically like a movie. It's animated pictures, basically.
The question is what about React Native apps? Well, this also applies to React Native apps, but there is an added complexity, the JS thread. Because most of your logic will run on the JS, most of your business logic probably resides on the JS side of things, you need to make sure that it's not too busy. For example, here I have this app with a Click Me button. When I click it, the state updates. I've been clicked one, two, three times, but Kill.js is too expensive, so when I click it, the JS side of things is blocked. So, even if I click Click Me a lot of times after clicking Kill.js, nothing happens, and it's not before Kill.js has finished that the JS actually becomes responsive again, and you can see it update four to 12 times like that. So, it's very important to take a look at the JS side of things as well, because your app could be running natively at 60 FPS but be completely unresponsive. This is why React Native offers this view, the React Native Performance Monitor, displaying Ui and JS FPS, and this is why we created this Flipper plugin, to be able to display it in a graph. Also, as an added bonus, it gives you a nice score for you to be able to run performance benchmarks. But, chances are, this score could depend on a lot of factors, actually, so let me give you some general tips on performance measures.
The first one is this. You should test on a lower-end device. I mean, if you only test on a high-end device, chances are that you will miss most of the issues that your users are actually could be having. An iPhone 13 can actually run JavaScript or some calculation 10 times as fast as a Samsung Galaxy A21s, so, well, you know what to do. You should definitely test on a lower-end Android device. Second tip is this. You should make your measures as deterministic as possible. Performance measures are hardly deterministic, so you can make several iterations and average the result. You can also make sure to keep the same conditions as much as possible for every measure, for example, network, the data you were loading, et cetera. And, I mean, if you want to reproduce the same conditions, it's ideal to be able to automate the behavior you want to test. And for that, you don't necessarily need an end-to-end testing framework.
Comments