Measuring
Performance
About me
Alexandre Moureaux
Tech LeadΒ @
Check out our open-source (github.com/bamlab) and our blog (blog.bam.tech)
60FPS: the Grail of Perf
-
FAST enough for good perceived smoothness
Β - Like a movie, it's
animated pictures
What
about
React Native
JS thread is important π₯
RN Perf Monitor
Introducing react-native-flipper-performance-monitor π₯³
4 Tips on
Performance
Measures
TIP 1
Test on a lower-end device
TIP 2
Make your measures deterministic
Make your measures deterministic
- Average your measures over several iterations.
Β - Keep the same conditions for every measure
Β - Automate the behavior you want to test.
PRO TIP: adb is awesome β€οΈ
TIP 3
Disable JS Dev mode
TIP 4
Use the best analysis tools
The best performance analysis tools
- JS Thread
- React DevTools
-
JS Flamegraph
Β
- UI Thread -> native tools
- Android: System trace profiler
- iOS: XCode instruments
A concrete example
TF1 Info
Our goal: π€©
- Low-end device
- JS FPS > 0
- UI FPS = 60
Following the 4 essential tips:
- Use a Samsung J3 2017
- Setup measures for 10s
- Reload with JS dev mode disabled
- Wait for feed to be loaded
- Hit "Start measuring"
- adb shell input swipe 500 1000 500 0 50
- Wait until the end of 10s
- Reproduce experience 5 times
-
Score average: 40/100 β
-
JS threadlock: 3.5-4s π±
-
UI thread: ~60 β
A neat option to activate
Browsing commits
Initial Render
RE-Render
vs
All our list children are RE-rendering
π±
ITERATION 1
Everyone should know this!
NB:
default windowSize
is 21 viewports
type State = {
first: number,
last: number,
};
renderItem is called on scroll by design
MEMO your list items
-
Score average:
40 -> 52 π -
JS threadlock: 3.7 -> 2.8s π
-
UI thread: ~60 β
ITERATION 2
The joy of nested lists π
Nested horizontal list renderItem is also called
When we scroll the parent vertical list
-
Score average: same π
-
JS threadlock: same π
-
UI thread: same π
ITERATION 3
Reducing carousel
re-render
loop prop adds 3 slides on each side
3 + 4 + 3 = 10 π€
-
Score average: 70/100 π
-
JS threadlock: 1s π
-
UI thread: ~60 β
π₯³
ITERATION 4
A non-intuitive fix? π€
Text
FlatList code
Memoized Slide
react-native-
snap-carousel
Nesting virtualized lists is TRICKY
YES
Can we avoid it? π€
-
Score average: 90/100 π₯³
-
JS threadlock: NONE β
-
UI thread: ~60 β
Measure your apps performance
Measure your apps performance
-
Take a low end Android device
Β -
Find areas with 0 JS FPS / < 60 UI FPS
Β - Analyze and fix them
Β - Check your score improvement π₯³
What's next?
- Automate measures
Β -
Add new metrics (TTI, ...)
Β -
Measure production apps
Β - Hopefully Lighthouse for mobile apps π€
Thank you!
: Β Β
) Β Β
Measuring and improving React Native Performance
By Alexandre Moureaux
Measuring and improving React Native Performance
- 395