Flashlight, a Lighthouse for Mobile Apps

Rate this content
Bookmark

The promise of Lighthouse is pretty cool, right? Visit any website, and with only a few clicks, you can get a performance score for it!

Wouldn’t it be grand if we had the same thing for React Native apps? 


Well, you’re in luck! let me present our new open source tool called Flashlight 🔦 

(cause you know, a Flashlight is basically a very small “mobile” lighthouse, right?)

7 min
23 Oct, 2023

Video Summary and Transcription

Today's Talk introduces Flashlight, a tool for measuring mobile app performance. Flashlight provides a performance report that highlights issues like high CPU usage on low-end devices. To fix these issues, the Shopify component Flashlist can be used. Flashlight can also be used locally to measure performance changes in React Native apps, with the ability to see the score rapidly changing and improved performance after implementing fixes. More information can be found in the documentation and an article comparing scrolling performance in React Native.

Available in Español

1. Introduction to Flashlight

Short description:

Hi, everyone. Today, I'm happy to talk about measuring mobile app performance and introduce our new tool called Flashlight. It's like a mobile Lighthouse. Just upload your Android app on app.flashlight.dev, configure the measurement, and get a performance report.

Hi, everyone. I'm Alex. I've been working with React Native for the past eight years at BAM, and today I'm very happy to talk to you about measuring mobile app's performance. I've always wanted to have an easy way to know whether the performance of my app was good or not. And I've always been jealous of web developers for Lighthouse. Have you ever used Lighthouse? You can go to any website and with it, with a simple few clicks, just generate a performance report and get a performance score for the web page you visited, which is pretty neat, right?

Wouldn't it be nice if we had something similar, but for mobile apps? Well, today I'm very proud to present you our new tool called Flashlight. It's meant as a mobile Lighthouse. So let's see how it works. You can go right now, if you like, on app.flashlight.dev and upload any Android app, iOS support is on the way. So let's say, for example, this is sharing my phone. We have an app like this, like I have sort of a Netflix clone. I can generate a release APK for it and upload it right here. And then I can configure what I want Flashlight to measure. So by default, you can measure app start performance quite easily. You just need to input here some text that will appear when the app has loaded. For example, here when my app has loaded, I know that family and history will appear so I can just input family here, and then click send me my performance report.

2. Analyzing Performance Report and Fixing Issues

Short description:

Now a new page opens, and after roughly 10 minutes, Flashlight provides a performance report. We can see that the app has high CPU usage, particularly in the JS Thread. This issue is highlighted by Flashlight, especially on low-end devices. To fix it, we can switch to using the Shopify component called Flashlist, which significantly improves performance.

Now a new page opens, depending on traffic, it should take roughly 10 minutes to finish and Flashlight to get the report. So I'm going to split this up a little bit. So when Flashlight is finally done, after roughly 10 minutes, this is what you would see. You would see that essentially what happened is that Flashlight has started the app 10 times and measured performance and what's really nice is that you have this see report button and if you click it, boom, you have your performance report. And in our case, we can see that it's pretty bad. Luckily, Flashlight gives us some performance metrics to understand why it's that bad.

Here we can see, for example, that this one here is the one that seems to be problematic. High CPU usage. We see that we have a thread using a lot of CPU for a lot of time, a thread called mqtjs. We can check the graphs. So we have frame rates, we have total CPU usage and we have CPU usage per thread and we can see again mqtjs in fact, basically for the whole duration of measure it's really really high. It uses way too much CPU. Okay, we can ask ourselves, what is mqtjs? You guessed it, it's the JS Thread. You never want this guy to be close to 100% of CPU usage because then that's the same as having zero JSFPS, your app would not respond to anything. The JS Thread is blocked. So, that's what happens when we open our app, basically, and flashlight is telling us we have a big issue. Note that actually Flashlight is running on a real low-end android device, a Samsung Galaxy A10s by default. So on a low-end device yeah, performance is really bad. What can we do to fix? Well, our app is basically a vertical list composed of horizontal nested lists. And we're using flat lists for both of those, horizontal and vertical. But let's see what happens if we change to using the Shopify component called Flashlist. Then we can just regenerate our APK and do exactly the same thing as before to get a new report with Flashlist. And boom! Ah, this is much better. We get a score of 75 out of 100. But what's really nice is we can actually go onto the history section here. We can click both reports, so the first one, MyAppWithFlatlist and the second one called Flashlist. And we can open the comparison view. We have the video as well. I'm just going to close them. And for example, if I jump to the CPU usage per thread, we can see quite easily that yeah, in green with Flashlist, CPU usage of the Jez thread is in fact much better with Flashlist.

3. Using Flashlight for Local Performance Measurement

Short description:

With Flashlight, you can measure performance changes in your app using our open source CLI. Install it easily and run 'Flashlight measure' on your plugged-in device with a React Native app. Start measuring scrolling performance and see the score rapidly changing. If there's an issue on the JS thread, implement a fix like switching to Flashlist. Reload and measure again to see improved performance. For more information, check out the docs at docs.flashlight.dev or an article comparing list scrolling performance in React Native between FlatList and FlashList. Feel free to reach out on Twitter or GitHub for any questions.

But what's nice with Flashlight is you can also use it locally to quickly measure performance changes in your app with our open source CLI. It's very simple to install. And then, for example, if you have a device plugged in with a React native app running, you can just run Flashlight measure. Then auto detect to automatically detect the currently focused app. And let's say I want to measure scrolling performance. I can hit start measuring. Start scrolling in my app. And it will measure the performance this scroll. You can see the score actually changing rapidly to a zero. Again, we have a massive issue on the JS thread when scrolling.

So let's say you implemented a fix. For example, switching from flat list to flash list. We can reload. And we can basically do the same thing again. Let's start measuring again. Scroll again. And we can see that now, performance is actually much better.

That's it for this short presentation of Flashlight. If you want to know more about what it can do, you can check out the docs at docs.flashlight.dev or you can also check out this article about comparing list scrolling performance in a React Native app between FlatList and FlashList, which goes into more details. Otherwise, if you have any questions you can also ping me on Twitter or GitHub.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
Top Content
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
JSNation 2023JSNation 2023
26 min
When Optimizations Backfire
Top Content
Ever loaded a font from the Google Fonts CDN? Or added the loading=lazy attribute onto an image? These optimizations are recommended all over the web – but, sometimes, they make your app not faster but slower.
In this talk, Ivan will show when some common performance optimizations backfire – and what we need to do to avoid that.

Workshops on related topic

React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
React Advanced Conference 2022React Advanced Conference 2022
81 min
Introducing FlashList: Let's build a performant React Native list all together
Top Content
WorkshopFree
In this workshop you’ll learn why we created FlashList at Shopify and how you can use it in your code today. We will show you how to take a list that is not performant in FlatList and make it performant using FlashList with minimum effort. We will use tools like Flipper, our own benchmarking code, and teach you how the FlashList API can cover more complex use cases and still keep a top-notch performance.You will know:- Quick presentation about what FlashList, why we built, etc.- Migrating from FlatList to FlashList- Teaching how to write a performant list- Utilizing the tools provided by FlashList library (mainly the useBenchmark hook)- Using the Flipper plugins (flame graph, our lists profiler, UI & JS FPS profiler, etc.)- Optimizing performance of FlashList by using more advanced props like `getType`- 5-6 sample tasks where we’ll uncover and fix issues together- Q&A with Shopify team
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
React Summit Remote Edition 2021React Summit Remote Edition 2021
60 min
How to Build an Interactive “Wheel of Fortune” Animation with React Native
Top Content
Workshop
- Intro - Cleo & our mission- What we want to build, how it fits into our product & purpose, run through designs- Getting started with environment set up & “hello world”- Intro to React Native Animation- Step 1: Spinning the wheel on a button press- Step 2: Dragging the wheel to give it velocity- Step 3: Adding friction to the wheel to slow it down- Step 4 (stretch): Adding haptics for an immersive feel