Approaching performance
when using React (but not only)
by Derek Stavis
Agenda
• Approaching performance

• Using tools to identify the root cause

• Common patterns avoid common problems
Quick plug about Brex
(and Vancouver)
The smartest card in the room
demands the smartest engineers
Fin ❤ tech
Expo, React Native, TypeScript,
SQLite, Objective-C, Java
Elixir, PostgreSQL, Functional
Programming, Distributed Systems
Come join us!
Come join us!
careers@brex.com
derek@brex.com
Or just 👋 to one of us
Enough of shameless plugs!
Let’s talk performance
The first thing you must know
Avoid prematurely optimizing for
performance without evidence
“I refactored this function and now it’s faster”
Use perceived performance to find
where to improve responsiveness
Responses below 100ms are perceived as instant — Jakob Nielsen
Use tooling to scientifically
find root causes
You’re considered wrong inaccurate until proven right otherwise
Focus on the 20% that will
give you 80% of results
Pareto never fails
Using tools to identify
the root cause
Let’s get into the weeds
React Dev Tools ⚛
The hunt for re-renders
Browser extension
Browser extension
Perform the actions you believe

are impacting performance
Browser Dev Tools 🛠
The hunt for expensive functions
Perform the actions you believe

are impacting performance
That’s not enough
Let’s demo!
But what about production?
React DevTools has a
production profiling bundle
React DevTools has a
production profiling bundle
Logging 📝
Common patterns avoid
common problems
Trivia Time
Can you spot performance issues here?
Can you spot performance issues here?
Can you spot performance issues here?
Can you spot performance issues here?
Can you spot performance issues here?
Can you spot performance issues here?
Avoid creating
new objects
when passing
as props
Use props and
dependency
inversion to bind
arguments to
handlers
Memoize the
selectors that
are run on the
render method
https://npmjs.com/package/memoize-one
Memoize the
callbacks you’re
using as well
Avoid reflows,
hence calls to
getBoundingClientRect
https://npmjs.com/package/react-select
And beware of
the libraries you
are using
packages/react-select/src/animated/transitions.js
81
82
83
…
84
85
JavaScript Showing the top two matches Last indexed on May 27, 2019
docs/App/Sticky.js
43
44
…
78
79
80
81
7 code results in JedWatson/react-select
or view all results on GitHub
Here we're invoking requestAnimationFrame with a callback
invoking our
call to getBoundingClientRect and setState in order to
resolve an edge case
around portalling. Certain portalling solutions briefly
remove children from the DOM
before appending them to the target node. This is to avoid
us trying to call getBoundingClientrect
while the Select component is in this state.
const offsetBottom = 88; // footer height
const { top: outerTop } = this.outerEl.getBoundingClientRect
();
const availableHeight = window.innerHeight;
let { height, width } = firstChild.getBoundingClientRect();
let scrollHeight;
That’s everything I had
I hope you learned something
If you like these challenges
Come join Brex!
Thanks!

React performance