Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Performance v2

Avatar for Steve Kinney Steve Kinney
February 02, 2026
2

React Performance v2

Avatar for Steve Kinney

Steve Kinney

February 02, 2026
Tweet

Transcript

  1. • You're looking for more insight into how React works.

    • You want to build a skillset and/or toolset for diagnosing performance issues in your React application. • You want to learn some ✨best practices✨ when building React applications in hopes of avoiding some performance issues down the road. It’s for you, of course. Who is this for?
  2. • React has a bunch of tools for caching and

    memoizing components. • But, you can also get a lot of bene fi ts for free just in the ways you structure your component hierarchy and application state. • Lastly, React has a bunch of super cool concurrency features. What are we going to cover? At a high level
  3. Throughout our time together, we’re going to work through a

    series of labs that are hyper-focused on one or two specific topics. The Labs
  4. • If you can solve a problem with how you

    shape your component hierarchy or state—do that first. • Memoization is a solid strategy only if the cost of checking pays for itself with the time you save rendering. • Using the Suspense API to progressively load your application is a good idea™. And, more good stu ff will come soon. • The Transition API is there for you when you’re really in a pickle. This will also be the last slide. I am going to show you this at the end.
  5. • Its state changed. • The context changed. • Its

    parent changed. State typically changes for one of three reasons. Anatomy of a Re-Render
  6. • Its state changed. • The context changed. • Its

    parent changed. • Its props changed. State typically changes for one of three reasons. Anatomy of a Re-Render
  7. So, then the name of the game is eliminating the

    unnecessary and prioritizing the urgent.
  8. Some themes. • Not doing stu ff is way faster

    than doing stu ff . (Component hierarchy & state management) • Seeing if you can skip doing stu ff is sometimes less work than doing stu ff . (Memoization + Compiler) • You can put off doing stu ff . (Suspense + Transitions) • Load as much as you need and as little as you can get away with. (Lazy loading + bundle optimization) for web performance… and life.
  9. • E ff ectively, we're not necessarily reducing the time

    it takes to render the UI, we're just trying to be a bit smarter about it. • React Fiber introduces this idea of priority as opposed to simply, dealing with requests in the order that they were received. What does that even mean? React Fiber
  10. It's basically a bunch of plain functions, a linked-list tree,

    and a small scheduler in a trench coat.
  11. • E ff ectively, we're not necessarily reducing the time

    it takes to render the UI, we're just trying to be a bit smarter about it. • React Fiber introduces this idea of priority as opposed to simply, dealing with requests in the order that they were received. • The key feature is that it can stop what it's doing and throw away an in- progress render whenever it feels like it. What does that even mean? React Fiber
  12. Basically, if something more important comes along, it can turn

    its focus and put the less important stuff on pause or toss it out for now and start over later.
  13. • Take the next Fiber. • Run beginWork(fiber, renderLanes). Basically,

    call the component function, derive the children. • If there are children, descend. If not, bubble up via completeWork to fi nalize the node, update the DOM, and collect any e ff ects. • But, along the way—ask Should I yield? If yes, pause for a moment and let the browser have the wheel back for a second. • Pick up where you left o ff . One thing at a time. The Rendering Phase
  14. • Urgent Updates: User input and stu ff like that.

    • Transition Updates: Stu ff explicitly marked as non-urgent by you. This is an over simpli fi cation, but go with it. Two Kinds of Updates
  15. • Every so often. Approximately after 5ms. • Are there

    any higher priority tasks waiting? How does React decide when to yield? Should I yield?
  16. If something comes in at a higher priority lane, React

    goes ahead and turns it attention to the more important thing.
  17. const SyncLane = 0b0000000000000000000000000000001; // Bit 1 const InputContinuousLane =

    0b0000000000000000000000000000100; // Bit 3 const DefaultLane = 0b0000000000000000000000000010000; // Bit 5 const TransitionLane1 = 0b0000000000000000000000001000000; // Bit 7
  18. • SyncLane: Immediate, blocking updates with (e.g. flushSync) • User

    actions (InputContinuousLane): Clicks, keypresses, dragging, scrolling. • DefaultLane: The normal course of business. • TransitionLanes: Stu ff explicitly put into a lower priority lane. • RetryLanes: Failed stu ff that we're waiting to retry. • IdleLane: The lowest priority work. A hand-wavy look at priorities. Lanes
  19. • Assigns the update to the appropriate lane. • Groups

    updates in the same lanes together. • Processes the lanes from the highest priority to the lowest. React puts things in their place. Lane Assignment
  20. Commits are never interrupted. We have a full tree of

    what the DOM should look like. Let’s make it happen. That's because we're actively changing the DOM at this point and stopping in the middle could leave us in an inconsistent state. The Commit Phase™
  21. • React calls any lifecycle methods or hooks that need

    to read the DOM before React mutates it. • No DOM writes yet, just reads. The Snapshot Phase Take a Picture
  22. • React applies all the changes it decided on during

    the render phase. • Creates, updates, or deletes DOM nodes. • Clean up any refs that no longer have nodes. • Runs passive e ff ect cleanups scheduled for this commit. Let’s change the DOM. Mutation
  23. • Perfect for measuring DOM layout or adjusting scroll positions

    • If you ever used useLayoutEffect, this is where that goes down. Changed, but not painted. Layout Phase
  24. • After the browser has painted, React schedules useEffect callbacks.

    • These run asynchronously, so they don't block the paint. • Great for data fetching, subscriptions, logging, timers, etc. All done—for now. Almost. Passive Effect
  25. All things are not equal… …in JavaScript. { foo: 1,

    bar: 2 } ! { foo: 1, bar: 2 } [1,2,3] ! [1,2,3] () = {} ! () = {}
  26. Let’s not get carried away with memoization Checking to see

    if you need to do stu ff is technically doing stu ff .
  27. • useMemo(): If it was expensive to get this value

    or it could trigger a render, but it’s really no di ff erent than last time—then just use the value we had last time,. • useCallback(): Actually don’t whip up a new function if nothing has changed. React has hooks to help. Some more tools
  28. • startTransition() is used when triggering an update (i.e. setState)

    in an event handler. • useDeferredValue() is used when receiving new data from a parent component (or an earlier hook in the same component). If I may quote from the documentation Two more hooks
  29. • If you can solve a problem with how you

    shape your component hierarchy or state—do that first. • Memoization is a solid strategy only if the cost of checking pays for itself with the time you save rendering. • Using the Suspense API to progressively load your application is a good idea™. And, more good stu ff will come soon. • The Transition API is there for you when you’re really in a pickle. The actual last slide. In conclusion