44
@lithinn Performance in React (Native) Anna Doubkova @ Hive

in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

  • Upload
    others

  • View
    47

  • Download
    0

Embed Size (px)

Citation preview

Page 1: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Performance in React (Native)

Anna Doubkova @ Hive

Page 2: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Performance

Page 3: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Patterns vs pre-optimisation

Page 4: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

IssuesThe actual ones

Slow startup time

Time to first interaction

Animation jagged/slow

Slow response to user action

Page 5: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

The weak link?

UI Thread JS ThreadRN Bridge

Page 6: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Looking for the culprit

Page 7: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Measuring JS performance

Page 8: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Page 9: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Page 10: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Measuring JS performance

Page 11: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

State change

Page 12: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Change

Render functions

New virtual dom tree

Reconciliation

Rendering

Page 13: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Should component update

the unexpected villain

Page 14: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Page 15: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Page 16: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Page 17: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Reconciler- Change node type -> re-mount- Change node prop/state -> re-render self & children

- Shallow equal

- Change propagates to all children

Page 18: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Node type change

Page 19: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Prop change

Page 20: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Recursive updates

Page 21: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Components

Page 22: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - anonymous functions

Page 23: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - anonymous functions

Page 24: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - react-redux

Page 25: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - react-redux

Page 26: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - selectors

Page 27: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Examples - selectors

Page 28: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

State - best practices

Page 29: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Local state - setting state based on props

Page 30: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Local state - setting state based on props

Page 31: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Local state - necessary?

Page 32: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Redux state - local

Page 33: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Redux state - batching

Page 34: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Connecting state

Page 35: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Connecting state

Page 36: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

General conclusions

For react web/RN

- It’s always the JS- Measure before acting- Think about reconciliation &

state updates- Memoise

Page 37: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

...or just use MobX

Page 38: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Native only

Page 39: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Native only - animations

Page 40: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Native only - inline requires

RAM bundler & Lazy Package

Page 41: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Native only - low-level measuring- Use profilers & systrace to check how your app is doing on low level

Page 42: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Native only - routing- React router native- React navigation- React native navigation

Page 43: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Optimise wisely

Page 44: in React (Native) Performance · Examples - react-redux. @lithinn Examples - react-redux. @lithinn Examples - selectors. @lithinn Examples - selectors. @lithinn State - best practices

@lithinn

Thank you!

Anna Doubkova @ Hive