React app performance - alexanderteplov/computer-science GitHub Wiki

React application performance

Measuring

  1. Profiler API
  2. Dev Tools Performance panel (based on 1.)
  3. Lighthouse

Optimizations

  1. delaying (lets us skip frequent updates)
    • debouncing, throttling (e.g., lodash debounce, throttle)
  2. memoizing (lets us skip excessive computations)
    • useEffect
    • useMemo
    • lazy initialization
      • with function argument of useState
      • with the third argument of useReducer
      • with a custom wrapper function for useRef
    • any third party helpers like lodash memoize
  3. avoiding reconciliation
    • PureComponent, shouldComponentUpdate
    • React.memo, the second argument function acts like shouldComponentUpdate
    • useMemo, useCallback
    • dispatch from useReducer (acts like useCallback)
    • immutable data structures let us widely use PureComponent/React.memo with a shallow comparison by default
  4. reducing overhead
    • function components over class components
    • using optimized production build
    • reducing dependencies, e.g., with partial import
  5. code-splitting
  6. SSR, SSG, or isomorphic app for some cases

Links

⚠️ **GitHub.com Fallback** ⚠️