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

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