completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

React performance

Measure what React re-renders on each key press, skip unchanged work with memo or the React Compiler, let the rest wait with transitions, and profile it.

By the end, you can
  • 01
    Find what ran, and whyCount the components one key press runs, and name each one's reason: its own state, its parent, or a context.
  • 02
    Skip what didn't changeUse memo with useMemo and useCallback, or the React Compiler, and say what each leaves for the browser to do.
  • 03
    Let the rest wait, and measure itKeep typing quick with useDeferredValue or a transition, and check the result with the Profiler, React DevTools and React's tracks.

Why do Asha's letters lag?

Module 36 takes the ideas of this course and looks at them through each framework's own tools. It starts with React.

Ravi's Mint tea page now has a page for its reviews: all 1,000 of them. As in lesson 35.3, each review is written in Markdown, and the marked library turns it into HTML. At the top sit a header with the cart, the price with Add to cart, and a box. Type a word in the box, and only the reviews that mention it stay. Ravi's newest touch: each review marks the word in yellow.

Asha wants to know what people say about honey. She types honey, a key every 120 ms, as in lesson 28.1. A millisecond (ms) is a thousandth of a second. On Ravi's page, she never sees her h. The box stays empty, then jumps to ho at 309.4 ms. Ravi tries one more change, and the h shows at 25.9 ms. Here are real frames from both pages:

Real frames of the reviews page as Asha typed honey. Highlight page: an empty box at her first key, then nothing new until 309.4 ms, when the box said ho, with the reviews for ho marked; then honey at 537.6 ms. Deferred page: the h at 25.9 ms, over all 1,000 reviews; ho at 262.3 ms, over the reviews for h; then honey with its reviews at 541.7 ms.Highlightfirst keyThe filter box, empty, over 1000 reviewsan empty box309.4 msThe box says ho, and the reviews that mention ho have it marked in yellowho, its reviews537.6 msThe box says honey, and the reviews that mention honey have it markedhoney, its reviewsDeferred25.9 msThe box says h, over the full list of 1000 reviewsh, the old list262.3 msThe box says ho, over the reviews for h, with h markedho, the list for h541.7 msThe box says honey, and the reviews that mention honey have it markedhoney, its reviews
Real frames from the course's recording on Asha's phone, in ms after her first key. On the highlight page, her h never showed on its own. On the deferred page, each letter showed at once, and the list followed.

Ravi's friends each have advice. "Wrap things in memo." "Turn on the React Compiler." "Use a transition." Which of them helps, and by how much? The course built the page six ways, one change at a time. Here is each page's slowest key:

The slowest key on six pagesPop out in the code editor (opens in a new tab)JavaScript
// Asha typed "honey" on six pages. Each page's slowest key,// in ms, is that visit's INP.const pages = [  ["As Ravi wrote it", 97.3],  ["memo only", 103.6],  ["memo, useMemo and useCallback", 56.9],  ["The React Compiler", 59.2],  ["Highlighting the word", 308.2],  ["Highlighting, with useDeferredValue", 141.1],]; for (const [page, inp] of pages) console.log(`${page}: ${inp.toFixed(1)} ms`);
  • Lines 1 and 2 are comments. INP, Interaction to Next Paint, is roughly a visit's slowest click, tap or key press, as lesson 26.1 showed. A good INP is 200 ms or less.
  • Lines 3 to 10 hold each page and its INP.
  • Line 12 prints As Ravi wrote it: 97.3 ms and memo only: 103.6 ms.
  • Then memo, useMemo and useCallback: 56.9 ms and The React Compiler: 59.2 ms.
  • Last, Highlighting the word: 308.2 ms and Highlighting, with useDeferredValue: 141.1 ms.

Two tools cut the first page's slowest key by about 40 ms. One did nothing. The marks tripled it, and a third tool cut that by more than half. Why? It comes down to how much of the page React runs for one letter, and when.

Real-life analogyReprinting the whole catalogue

Ravi's shop sends out a printed catalogue. When one price changes, his printer reprints all 1,000 pages. Then someone compares each new page with the old one, and swaps in the one that changed. The swap takes a minute. The reprinting takes all morning.

In real life: One price changes
In React: Asha types one letter
In real life: Reprinting all 1,000 pages
In React: React running every component again: a render
In real life: Comparing each new page with the old one
In React: React working out what differs
In real life: Swapping in only the changed page
In React: The commit: React changes only what differs
The main idea

A re-render is React calling your components again. Much of a slow key can be components that ran and changed nothing. Skip them with memo or the React Compiler. If the work is real, let it wait with a transition. And measure first, with React's Profiler and its tracks.

How the course recorded it

  • Ravi's page: 1,000 reviews, built with React 19.3.1 for production. Every page has the same reviews and the same layout.
  • Six pages: each one change away from another. Each was built twice: for production, and with React's profiling build, which the last section explains.
  • Asha's phone: Chrome 157, in a window 412 by 480 pixels, with the CPU 4 times slower, as in lessons 28.1 to 28.3.
  • Real keys: sent through Chrome's DevTools protocol. Each key went down, then up 60 ms later. Chrome passes key presses straight to the page.
  • Five visits: each page and build ran 5 times, taking turns. The lesson quotes the visit with the middle INP.
  • Counting: in the profiling build only, the course added one line to the top of each component. It counts how often that component runs. The page was also cross-origin isolated, as in lesson 29.3. MDN says that gives the page's clock steps of 5 microseconds (µs), not 100 µs. React's timers use that clock.

Three reasons a component runs again

Start with the page as Ravi first wrote it, with no marks. Here is its main component, App. It holds the box's text, the cart, and the reviews people found helpful:

app-naive.jsx: the App componentJSX
export function App() {  const [query, setQuery] = useState("");  const [cart, setCart] = useState(0);  const [votes, setVotes] = useState([]);  const shown = REVIEWS.filter((review) => matches(review, query));  const shop = { cart, addToCart: () => setCart(cart + 1) };  function markHelpful(id) {    setVotes([...votes, id]);  }  return (    <ShopContext value={shop}>      <Header />      <main>        <h1>Mint tea reviews</h1>        <p className="buy">£4.80 for 100 g <AddButton /></p>        <FilterBox query={query} onChange={setQuery} />        <ReviewList query={query} reviews={shown} votes={votes} onHelpful={markHelpful} />      </main>    </ShopContext>  );}
  • Lines 2 to 4 make three pieces of state: query is the box's text, cart counts the cart, and votes lists the helpful reviews.
  • Line 5 keeps the reviews that mention the box's text.
  • Line 6 makes shop, an object with the cart and a function that adds to it.
  • Lines 7 to 9 make markHelpful. Each review's Helpful button calls it.
  • Line 11 hands shop to a context. A context lets components deep in the page read a value without props. The cart badge in Header reads it, and so does AddButton.
  • Line 16 draws the box. Each key calls setQuery with the box's new text.
  • Line 17 draws the list. ReviewList draws one Review per review. Each Review runs marked on its words, and draws Stars, which draws five Star components.

When Asha types h, setQuery changes App's state. React then renders: it calls App again, to work out what the page should look like. The course counted every component that ran:

What ran for the hPop out in the code editor (opens in a new tab)JavaScript
// The components that ran for Asha's h on the naive page, as the page counted them.const ran = { App: 1, Header: 1, CartBadge: 1, AddButton: 1, FilterBox: 1, ReviewList: 1, Review: 900, Stars: 900, Star: 4500 };const total = Object.values(ran).reduce((sum, count) => sum + count, 0); console.log(`${total} components ran for one letter.`);console.log(`Review ran ${ran.Review} times, and Star ${ran.Star} times.`);
  • Line 2 holds what the page counted for the h, component by component.
  • Line 3 adds them up.
  • Lines 5 and 6 print 6306 components ran for one letter. and Review ran 900 times, and Star 4500 times.

Yet the page barely changed. The box gained a letter, and the line above the list changed. The list went from 1,000 reviews to 900. The other 900 were exactly the same. So why did they run? React's docs give the reasons, and there are three:

  • Its own state changed. App ran because query changed.
  • Its parent rendered. Everything else in App ran with it. React's docs say rendering goes down the tree: if a component returns other components, React renders those next.
  • A context it reads changed. CartBadge and AddButton read the context. Line 6 makes a new shop object each time App runs. To React, a new object is a new value, even with the same cart inside.

Why does a parent's render reach its children? Each time App runs, its JSX makes new elements, and each gets a new props object. For every component, React's ReactFiberBeginWork.js checks oldProps !== newProps (lines 4251 to 4262). A new object is never the old one, so the child runs, even when every prop inside is the same.

React's own timer, the Profiler, put the render at 44.9 ms. Then React changed the page. Its docs say it "only changes the DOM nodes if there's a difference between renders." So most of those 6,306 runs found nothing to change. Why it matters: on this page, a key's cost comes from what runs, not from what changes. The React lesson When React re-renders shows the three reasons with small examples.

Pick a page to see what ran for each of Asha's keys. The next two sections explain the other three pages.

Playground: what ran for each key
Naive: the h
  1. Appran 1 time
  2. · Headerran 1 time
  3. · · CartBadgeran 1 time
  4. · AddButtonran 1 time
  5. · FilterBoxran 1 time
  6. · ReviewListran 1 time
  7. · · Reviewran 900 times
  8. · · · Starsran 900 times
  9. · · · · Starran 4,500 times
Naive: each key
  1. h: 6,306 components ranrender 44.9 ms, key 97.3 ms
  2. o: 2,456 components ranrender 17.5 ms, key 61.2 ms
  3. n: 1,756 components ranrender 11.3 ms, key 36.2 ms
  4. e: 1,756 components ranrender 9.6 ms, key 21.3 ms
  5. y: 1,406 components ranrender 9.6 ms, key 27.2 ms
Try it yourself
Naive: 6,306 components ran for the h

Pick a page. The first list is every component on the page, with how many times it ran for Asha's h. The second list is her five keys: the components that ran, React's render time, and the key's time as INP counts it.

From the course's recording in Chrome 157, with the CPU slowed 4 times: components and render times from React's profiling build, key times from its production build, the middle of 5 visits.

Skip what didn't change: memo, useMemo and useCallback

memo wraps a component. It tells React to skip that component when its props are the same as last time. React's docs say it compares each prop with Object.is. The React lesson memo, useMemo and useCallback teaches it. Ravi's first try adds two lines:

app-memo-only.jsx: two lines of memoJSX
const MemoHeader = memo(Header);
const MemoReview = memo(Review);

Line 1 wraps the header. Line 2 wraps each review, and the list draws MemoReview. Here is the h on three pages:

The h, with and without memoPop out in the code editor (opens in a new tab)JavaScript
// Asha's h on three pages: the components that ran, React's render time,// and the key's time, in ms.const pages = [  ["As Ravi wrote it", 6306, 44.9, 97.3],  ["memo only", 6305, 44.6, 103.6],  ["memo, useMemo and useCallback", 4, 6.2, 56.9],]; for (const [page, ran, render, key] of pages) {  console.log(`${page}: ${ran} ran, render ${render} ms, key ${key} ms`);}
  • Lines 4 to 6 hold each page: the components that ran for the h, React's render time, and the key's time.
  • Line 10 prints As Ravi wrote it: 6306 ran, render 44.9 ms, key 97.3 ms.
  • Then memo only: 6305 ran, render 44.6 ms, key 103.6 ms.
  • Last, memo, useMemo and useCallback: 4 ran, render 6.2 ms, key 56.9 ms.

memo alone saved one component: Header. Every review still ran. So did CartBadge, inside the skipped header. What went wrong?

Real-life analogyA ticket check at the door

A club lets you skip the queue if you show the same ticket as last time. The guard checks the serial number. If you bring a fresh photocopy each week, it has a new number. So you queue again, though the ticket looks the same.

In real life: The guard at the door
In React: memo
In real life: Checking the ticket's serial number
In React: Object.is: the same object, not just an equal one
In real life: A fresh photocopy of the same ticket
In React: A new function or object made in this render
In real life: Keeping the same ticket in your wallet
In React: useCallback and useMemo

Here is the same thing in JavaScript. render makes a function and an object, the way App does:

Two renders, two new functionsPop out in the code editor (opens in a new tab)JavaScript
function render() {  return { onHelpful: (id) => id, shop: { cart: 0 } };} const first = render();const second = render();console.log(Object.is(first.onHelpful, second.onHelpful));console.log(Object.is(first.shop, second.shop));console.log(Object.is(first.shop.cart, second.shop.cart));
  • Lines 1 to 3 return a new function and a new object each time render runs.
  • Lines 5 and 6 call it twice, like two renders.
  • Line 7 prints false: two different functions, though their code is the same. Line 8 prints false: two objects.
  • Line 9 prints true: the number inside is the same 0.

That's the memo-only page. App made a new markHelpful on every render, and passed it to every review as onHelpful. memo found a new function, so the review ran. React's code shows it. shallowEqual compares each prop with Object.is (shallowEqual.js, line 45). A memo component skips only if that check passes (ReactFiberBeginWork.js, lines 559 to 561).

memo can't stop a context either. Before it skips, React checks the component's own state and its contexts (line 584). The context check uses Object.is too (ReactFiberNewContext.js, line 531). So App's new shop object reached CartBadge straight through the skipped header.

The fix keeps the same values from render to render. The memo page changes four lines in App:

app-memo.jsx: the same values, keptJSX
const shown = useMemo(() => REVIEWS.filter((review) => matches(review, query)), [query]);
const addToCart = useCallback(() => setCart((count) => count + 1), []);
const shop = useMemo(() => ({ cart, addToCart }), [cart, addToCart]);
const markHelpful = useCallback((id) => setVotes((list) => [...list, id]), []);
  • Line 1: useMemo keeps the filtered list until query changes. React's docs say it caches "the result of a calculation between re-renders."
  • Line 2: useCallback keeps the same addToCart function. The empty list at the end says nothing it uses can change.
  • Line 3 keeps the same shop object until the cart changes.
  • Line 4 keeps the same markHelpful. It passes a function to setVotes, so it never needs the current votes.

Now only 4 components ran: App, AddButton, FilterBox and ReviewList. AddButton ran because it isn't wrapped in memo, and its parent rendered. React's render took 6.2 ms instead of 44.9.

So why did the key still take 56.9 ms? Its handlers, with React's render and commit, took 24.6 ms. Then 31.8 ms passed before the next frame, while the browser worked on a page of 900 reviews. memo can't shrink that. Why it matters: memo cut React's part of the key, not the browser's.

Let the React Compiler add the memo

Hand-written memo is easy to break. One new function undid all of it. The React Compiler does this work for you. It is a build tool: it rewrites your components before they ship. Its first stable version, 1.0, came out on October 7, 2025. It runs as a plugin for Babel, a tool that rewrites JavaScript, and its docs say it must run first among Babel's plugins.

The course compiled the naive page's code as it was, with no memo at all. It used babel-plugin-react-compiler 1.0.0. Here is the start of Review, exactly as the compiler wrote it:

review.jsx after the compiler, shortenedJavaScript
export function Review(t0) {  const $ = _c(23);  const {    review,    query,    voted,    onHelpful  } = t0;  let t1;  if ($[0] !== query || $[1] !== review.text) {    t1 = marked.parse(query ? highlight(review.text, query) : review.text);    $[0] = query;    $[1] = review.text;    $[2] = t1;  } else {    t1 = $[2];  }  const html = t1;
  • Line 2 asks React for a small array of 23 saved values, kept with this component. _c comes from react/compiler-runtime, which calls React's useMemoCache (ReactFiberHooks.js, line 1181).
  • Lines 3 to 8 take the props apart, as Review did.
  • Line 10 checks two saved values: the query and the review's words.
  • If either changed, lines 11 to 14 run marked again and save the result.
  • Otherwise, line 16 takes the saved HTML, and marked doesn't run.

The rest of the function does the same for each part of the review. If nothing changed, it returns the very same <li> element as last time.

Real-life analogyA cook's labelled bowls

Before the rush, a cook fills bowls and labels each with what went in. When an order comes, she reads the label. If it matches, she uses the bowl as it is. She only chops again when the order asks for something new.

In real life: A bowl of chopped mint, with a label
In React: A saved value, with the inputs it came from
In real life: Checking the label against the order
In React: if ($[0] !== query || $[1] !== review.text)
In real life: Using the bowl as it is
In React: Returning the saved value
In real life: Chopping again for a new order
In React: Running marked again for new words
The h, by hand and compiledPop out in the code editor (opens in a new tab)JavaScript
// Asha's h: the components that ran, React's render time and the key's time, in ms.const memoPage = { review: 0, stars: 0, render: 6.2, key: 56.9 };const compiled = { review: 900, stars: 0, render: 11.4, key: 59.2 }; for (const [page, h] of Object.entries({ memoPage, compiled })) {  console.log(`${page}: Review ran ${h.review} times, Stars ${h.stars}; render ${h.render} ms, key ${h.key} ms`);}
  • Lines 2 and 3 hold the h on the memo page and on the compiled page.
  • Line 6 prints memoPage: Review ran 0 times, Stars 0; render 6.2 ms, key 56.9 ms.
  • Then compiled: Review ran 900 times, Stars 0; render 11.4 ms, key 59.2 ms.

Review still ran 900 times. The compiled ReviewList made new elements when the list changed, so React called each Review. But each call found its saved values unchanged, and returned its old <li>. React's check from earlier, oldProps !== newProps, then found the same props below it. So Stars and Star never ran.

The components that ran for Asha's h, on three pages. As Ravi wrote it: ran App 1, Header 1, CartBadge 1, AddButton 1, FilterBox 1, ReviewList 1, Review 900, Stars 900, Star 4,500. memo, useMemo, useCallback: ran App 1, AddButton 1, FilterBox 1, ReviewList 1; skipped Header, CartBadge, Review, Stars, Star. React Compiler: ran App 1, FilterBox 1, ReviewList 1, Review 900; skipped Header, CartBadge, AddButton, Stars, Star.As Ravi wrote itApp 1Header 1CartBadge 1AddButton 1FilterBox 1ReviewList 1Review 900Stars 900Star 4,500memo, useMemo, useCallbackApp 1HeaderCartBadgeAddButton 1FilterBox 1ReviewList 1ReviewStarsStarReact CompilerApp 1HeaderCartBadgeAddButtonFilterBox 1ReviewList 1Review 900StarsStar
Each card is a component, under the one that draws it, with how many times it ran for the h. A crossed-out card didn't run, like a gray bar in React DevTools.

It isn't free. The compiled page's JavaScript was 1.3 KB bigger, gzipped: all those checks. The docs add a few more facts:

  • It follows the Rules of React. When code breaks them, it "safely skips optimization" there.
  • A "use no memo" line at the top of a component tells it to skip that one.
  • In React DevTools, compiled components show a "Memo ✨" badge.
  • useMemo and useCallback still work beside it, as "an escape hatch".

Why it matters: from the naive code, the compiler did about as well as careful memo by hand. The React lesson The React Compiler shows how to turn it on.

When every review must change: transitions and Suspense

Now back to the page in Asha's frames. Ravi added the marks to the memo page. Each review now gets the box's text:

app-highlight.jsx: each review gets the queryJSX
<MemoReview key={review.id} review={review} query={query} voted={votes.includes(review.id)} onHelpful={onHelpful} />

That one prop, query={query}, changes for every review on every key. memo sees a new value, so every review runs. So does the compiler's check. Nothing can be skipped, because every review really changes.

Five keys, with marks and with a deferred valuePop out in the code editor (opens in a new tab)JavaScript
// Asha's five keys: how long each took, as INP counts it, in ms.const highlight = { h: 308.2, o: 190.5, n: 195.1, e: 76.3, y: 58.3 };const deferred = { h: 23.7, o: 141.1, n: 66.4, e: 25.1, y: 11.3 }; for (const letter of "honey") {  console.log(`${letter}: ${highlight[letter]} ms, then ${deferred[letter]} ms`);}
  • Lines 2 and 3 hold each key's time on the two pages.
  • Line 6 prints one line per key: h: 308.2 ms, then 23.7 ms, and so on, to y: 58.3 ms, then 11.3 ms.

On the highlight page, the h took 308.2 ms. React marked 900 reviews. The o arrived meanwhile, and its handlers ran before any frame. The h and the o shared one frame, which is why Asha never saw her h alone.

The deferred page adds two lines to App, and wraps the list in memo:

app-deferred.jsx: the list gets a deferred copyJSX
const deferredQuery = useDeferredValue(query);const shown = useMemo(() => REVIEWS.filter((review) => matches(review, deferredQuery)), [deferredQuery]);
  • Line 1 asks React for a deferred copy of query: a copy allowed to lag behind. The React lesson Deferred values teaches it.
  • Line 2 filters with the deferred copy. The list, wrapped in memo as MemoList, gets the deferred copy too. The box still gets the real query.

On each key, React first renders with the old copy. The list's props haven't changed, so memo skips it. The box shows the letter at once: the h took 23.7 ms. Then React renders the list "in the background with the new value", as its docs say. If another key comes first, React starts that work again with the newer value. It never put the list for ho on the page. The lists it did put there were for h, hon, hone and honey.

The main thread for Asha's first 320 ms, to scale. Highlight: busy from 0.2 ms to 320.0 ms; keys at h 0.0 ms, o 117.7 ms, n 238.6 ms; ho shows, 309.4 ms. Deferred: busy from 0.3 ms to 22.1 ms, from 23.5 ms to 84.3 ms in React's small pieces, from 84.3 ms to 264.8 ms, from 268.3 ms to 275.3 ms, from 276.0 ms to 286.7 ms in React's small pieces, from 287.1 ms to 320.0 ms; keys at h 0.0 ms, o 119.2 ms, n 239.2 ms; h shows, 25.9 ms, ho shows, 262.3 ms.Highlighthonho shows, 309.4 msDeferredhonh shows, 25.9 msho shows, 262.3 ms0 ms320 ms
From Chrome's trace, to scale, in ms after the h. Each letter above a lane marks a key going down. Light bars are React's pieces of about 5 ms; plain bars ran in one go. On the deferred page, the h ran alone, but the o waited behind one long stretch: the list's commit, then the browser's style and layout.
Real-life analogyThe score and the stats screen

At a match, the operator changes the score the moment a goal goes in. The stats screen takes longer, so she redraws it between goals. If another goal comes first, she starts again with the new numbers. When the stats are ready, they go up all at once.

In real life: Changing the score the moment a goal goes in
In React: The box: an urgent update
In real life: Redrawing the stats between goals
In React: The list: rendered with the deferred copy
In real life: Starting the stats again after another goal
In React: Dropping the list for ho
In real life: Putting all the stats up at once
In React: The commit, which can't be split

But the o took 141.1 ms, the slowest key on the page. What did it wait for?

What the o waited forPop out in the code editor (opens in a new tab)JavaScript
// What the o waited for on the deferred page, from Chrome's trace, in ms.const lastPiece = 64.9; // the rest of the h's list, and its commitconst style = 13.5;const layout = 51.7; console.log(`React's last piece: ${lastPiece} ms`);console.log(`The browser's style and layout: ${(style + layout).toFixed(1)} ms`);console.log(`The o waited 96.3 ms in all.`);
  • Lines 2 to 4 hold three times from Chrome's trace.
  • Lines 6 to 8 print React's last piece: 64.9 ms, The browser's style and layout: 65.2 ms and The o waited 96.3 ms in all.

React renders a deferred list in pieces of about 5 ms, with the main thread free between them, as lesson 28.3 showed. But it puts the finished list on the page in one go. Then the browser lays out every marked review in one go too. The o arrived during React's last piece, which ended with that commit. Why it matters: a deferred value moves React's render out of the way. It can't split the commit, or the browser's work after it.

A transition is a state update you mark as not urgent. startTransition marks one where you set the state, and works the same way. Lesson 28.3 measured both and found almost the same result. React's docs give the rule: use startTransition when you own the state's set function, and useDeferredValue when you only get the value. Pick a page to see each of Asha's keys:

Playground: Asha's five keys, six ways
Highlight: each key
  1. h, pressed at 0.0 mstook 308.2 ms
  2. waited 0.8 mslist for "h" put on the page at 120.2 ms
  3. o, pressed at 117.7 mstook 190.5 ms
  4. waited 73.2 mslist for "ho" put on the page at 251.2 ms
  5. n, pressed at 238.6 mstook 195.1 ms
  6. waited 61.3 mslist for "hon" put on the page at 338.8 ms
  7. e, pressed at 357.4 mstook 76.3 ms
  8. waited 18.8 mslist for "hone" put on the page at 404.0 ms
  9. y, pressed at 476.6 mstook 58.3 ms
  10. waited 3.0 mslist for "honey" put on the page at 507.4 ms
Try it yourself
Highlight: the slowest key took 308.2 ms

Took is the key as INP counts it, from the key going down to the next frame. Waited is the part before its handlers could start. A list React never put on the page was dropped for a newer one.

From the course's recording in Chrome 157, with the CPU slowed 4 times: times in ms after Asha's first key, from React's production build, the middle of 5 visits.

Suspense keeps the old reviews on screen

Transitions do one more job. A <Suspense> boundary shows a fallback, like "Loading", while the content inside it waits for code or data. Lessons 35.2 and 35.3 used boundaries to stream a page and to hydrate it in parts. Say Ravi adds a Newest first button, and the newest reviews load inside a boundary:

Newest first, in a transitionJSX
function showNewest() {  startTransition(() => {    setOrder("newest");  });}

Line 2 marks the update as a transition. Line 3 asks for the newest reviews. React's docs say what happens next. Without a transition, the reviews on screen would vanish behind the fallback until the new ones came. With one, React keeps showing the current reviews. It "only waits long enough to avoid hiding already revealed content", so new boundaries still show their fallbacks. The docs add that routers built for Suspense are expected to wrap their navigations in transitions.

Why it matters: React's docs call a fallback that replaces visible content "a jarring user experience." The React lesson Suspense has the details.

Measure it: the Profiler, React DevTools and React's tracks

Most numbers so far came from tools you can use too. Here are three.

Real-life analogyAn itemised receipt

A shop's total tells you how much you spent. Only the itemised receipt tells you what you paid for. When the total is high, you read the lines.

In real life: The total at the bottom
In React: INP: one number for the whole key
In real life: Each line, with its price
In React: Each component, with its render time
In real life: Things you didn't buy aren't listed
In React: Components that didn't run

The Profiler in your code

<Profiler> is a React component that times the tree inside it. React calls its onRender function after each commit. Here is the naive page's entry file:

main-naive.jsx: App inside a ProfilerJSX
import { Profiler } from "react";import { createRoot } from "react-dom/client";import { App } from "./app-naive.jsx";import { onRender } from "./record.js"; createRoot(document.querySelector("#root")).render(  <Profiler id="reviews-page" onRender={onRender}>    <App />  </Profiler>,);
  • Line 1 imports Profiler. Line 4 imports onRender, the course's function that keeps each report.
  • Lines 7 to 9 wrap App in it. id names the part of the page being measured.
  • React calls onRender with the id, the phase and four times. Two of them matter here. actualDuration is how long this render took. baseDuration is about how long rendering the whole tree again would take, from each component's last render.
The Profiler's report for the h, on the memo pagePop out in the code editor (opens in a new tab)JavaScript
// The Profiler's onRender for Asha's h on the memo page, in ms.
const actualDuration = 6.2;
const baseDuration = 83.7;

console.log(`React rendered for ${actualDuration} ms.`);
console.log(`Rendering the whole tree again would take about ${baseDuration} ms.`);

Lines 5 and 6 print React rendered for 6.2 ms. and Rendering the whole tree again would take about 83.7 ms. React's docs say to compare the two "to see if memoization is working."

There's a catch. React's docs say profiling "is disabled in the production build by default." You need React's profiling build. Import from react-dom/profiling instead of react-dom/client, or let your bundler swap them, as the course did. It costs time:

The slowest key, production build and profiling buildPop out in the code editor (opens in a new tab)JavaScript
// Each page's slowest key, in ms, with React's production build
// and with its profiling build.
const naive = { production: 97.3, profiling: 138.5 };
const highlight = { production: 308.2, profiling: 367 };

for (const [page, key] of Object.entries({ naive, highlight })) {
  console.log(`${page}: ${key.production} ms, then ${key.profiling} ms`);
}

Line 7 prints naive: 97.3 ms, then 138.5 ms and highlight: 308.2 ms, then 367 ms. Why it matters: use the profiling build to find what runs. Quote INP from the production build.

React DevTools' Profiler

React DevTools is a browser extension. Its Profiler tab records each commit while you use the page. Its flame chart shows every component as a bar. A gray bar "did not render at all during this commit", says the React blog post that introduced it. Two of its settings help with this lesson's question:

  • Record why each component rendered while profiling. Each component then shows "Why did this render?". One of its answers is "The parent component rendered." Others name the props or state that changed.
  • Highlight updates when components render. The page highlights each component as it renders, so you can see how much runs for one key.

The React lesson Profiling React apps walks through the DevTools Profiler step by step.

React's tracks in Chrome's Performance panel

React 19.2 added its own tracks to Chrome's Performance panel. React writes them with console.timeStamp, a Chrome API built for adding entries "with minimal overhead". They appear with development builds and profiling builds. There are two kinds:

  • Scheduler ⚛ shows React's work by priority, in four tracks: Blocking, Transition, Suspense and Idle. Each update shows its steps, such as Render, Commit and Remaining Effects. Remaining Effects is when React runs effects such as useEffect.
  • Components ⚛ shows each component's render as a bar, like the flame chart. In a profiling build, only components inside a <Profiler> appear.
React's Scheduler track for Asha's h, to scale, in ms after the key. Naive page, all in the Blocking track: Blocking Render from 8.6 ms, 52.3 ms; Blocking Commit from 60.9 ms, 19.5 ms; Blocking Remaining Effects from 80.4 ms, 24.2 ms. Deferred page: Blocking Render from 7.3 ms, 2.9 ms; Blocking Commit from 10.2 ms, 1.0 ms; Transition Render from 22.3 ms, 79.8 ms; Transition Commit from 102.2 ms, 67.3 ms.Naive page, all in the Blocking trackRender, 52.3 msCommit, 19.5 msRemaining Effects, 24.2 msDeferred pageBlocking: Render, 2.9 msBlocking: Commit, 1.0 msTransition: Render, 79.8 msTransition: Commit, 67.3 ms0 ms: the h goes down
From React's profiling build, as Chrome's Performance panel shows it, to scale. Light bars are in the Transition track. On the deferred page, the list's render and commit came after the h's own tiny render.

On the naive page, the h's Render took 52.3 ms, and its Commit 19.5 ms, both in Blocking. Render spans React's whole render pass, so it's a little longer than the Profiler's actualDuration. On the deferred page, the list's Render, 79.8 ms, and its Commit, 67.3 ms, came after the h's own tiny render.

Remaining Effects took 24.2 ms on the naive page, but 4.2 ms on the memo page. In a profiling build, React writes the Components track in that step (ReactFiberCommitWork.js, lines 3885 to 3890). More components ran, so there was more to write.

One warning: the Components track can miss very quick components. To list renders, React walks into a part of the tree only if its measured time isn't 0, unless it has effects to run (lines 3796 to 3803). For the h, the track listed Review 900 times, but Star only 2,655 times, not 4,500. Pick a page to see its Scheduler entries for the h:

Playground: the Scheduler track for the h
Naive: Scheduler ⚛
  1. Blocking: Event: input3.6 ms, from 4.8 ms
  2. Blocking: Update0.2 ms, from 8.4 ms
  3. Blocking: Render52.3 ms, from 8.6 ms
  4. Blocking: Commit19.5 ms, from 60.9 ms
  5. Blocking: Waiting0.0 ms, from 80.4 ms
  6. Blocking: Remaining Effects24.2 ms, from 80.4 ms
Try it yourself
Naive: React's entries for the h

Each row is one entry in the Scheduler ⚛ group of Chrome's Performance panel: its track, its name, how long it lasted, and when it started, after the h went down. Only the entries that started before the next key are listed.

From the course's recording in Chrome 157, with the CPU slowed 4 times: from React's profiling build, the middle of 5 visits.

Which tool for which slow interaction?

Read this table across. Each row is one page, and what Asha's h cost on it.

Six pages, one letter
PageWhat changedWhat ran for the hReact's render for the hThe slowest key
As Ravi wrote itNothing: App keeps all the state.6,306 components, 900 of them Review.44.9 ms.97.3 ms, on the h.
memo onlymemo around the header and each review.6,305 components, 900 of them Review.44.6 ms.103.6 ms, on the h.
memo, useMemo and useCallbackmemo, with useMemo and useCallback keeping values the same.4 components, 0 of them Review.6.2 ms.56.9 ms, on the h.
The React CompilerThe naive code, run through the React Compiler.903 components, 900 of them Review.11.4 ms.59.2 ms, on the h.
Highlighting the wordThe memo page, with each review marking the word.6,304 components, 900 of them Review.56.0 ms.308.2 ms, on the h.
Highlighting, with useDeferredValueThe highlight page, with a deferred copy of the word for the list.6,307 components, 900 of them Review.60.0 ms.141.1 ms, on the o.

Now sort these slow spots by what can help:

Skip it, let it wait, or shrink it?
  • The header runs again on every key, with the same props
  • Every review runs again because onHelpful is a new function each time
  • A context value object made fresh in the parent's render
  • Each review marks the word being typed
  • A chart that redraws for every position of a slider
  • A tab whose new data suspends, while the old tab's content is on screen
  • A button that puts 10,000 new rows in the page at once
  • The browser's style and layout for 900 reviews after each key
Try it yourself
0 of 8 correct

Sort each slow spot by what can help it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

The React lesson Performance patterns adds more ways to run less, such as moving state down to the part that uses it.

Common mix-ups

  • "A re-render rewrites the page." No. For the h, the naive page ran 6,306 components. React changed only the box, the line above the list, and the list's length.
  • "memo stops a component from running." No. It skips only when every prop is the same object as before. A new function ran all 900 reviews, and a new context value reached CartBadge.
  • "With the React Compiler, components don't run." No. Review ran 900 times for the h. Each run found its saved values and returned its old element.
  • "useDeferredValue makes the list render faster." No. The list did the same work, later. The o still waited 96.3 ms behind its commit.
  • "Measure INP with the profiling build." No. The profiling build was slower: 97.3 ms became 138.5 ms on the naive page.
  • "The Components track lists every render." No. Very quick components can be missing. Star appeared 2,655 times, of 4,500.

Practice exercises

Answer each one first, then open the hints if you need them.

Exercise 1 · Warm-upWhich prop changed?

memo compares each prop with Object.is. Which props of this review does it see as changed?

Starter codePop out in the code editor (opens in a new tab)JavaScript
const markHelpful = (id) => id;
const before = { review: 7, voted: false, onHelpful: markHelpful };
const after = { review: 7, voted: false, onHelpful: (id) => markHelpful(id) };

const changed = Object.keys(after).filter((key) => !Object.is(before[key], after[key]));
console.log(changed.join(", ") || "nothing");

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upHow much did memo skip?

    These are the memo page's two Profiler times for the h. What does it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    const actualDuration = 6.2;
    const baseDuration = 83.7;
    
    const skipped = 1 - actualDuration / baseDuration;
    console.log(`React skipped about ${Math.round(skipped * 100)}% of the tree's cost.`);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeThe o on the compiled page

      On the compiled page, how many components ran for Asha's o?

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeThe n on the highlight page

        On the highlight page, how long did the n wait before its handlers could start, in ms?

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeA blocked update in DevTools

          Open the course's trace of the deferred page, made with the profiling build, in Chrome's DevTools. In the Blocking track, what is the entry right after the o's Event: input?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeHow often Suspense reveals

            React's docs say how often, at most, React reveals content that was waiting in a Suspense boundary. Once every how many ms?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask two things: did the component's output really change, and could the work wait?

              The React performance quiz · 7 questionsScore: first tries count
              1. Question 1 of 7In React's docs, what does "rendering" mean?

                Choose an answer to see the explanation.

              2. Question 2 of 7On the memo-only page, why did every review still run for the h?

                Choose an answer to see the explanation.

              3. Question 3 of 7What does this Object.is example print on its third line?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                function render() {
                  return { onHelpful: (id) => id, shop: { cart: 0 } };
                }
                
                const first = render();
                const second = render();
                console.log(Object.is(first.onHelpful, second.onHelpful));
                console.log(Object.is(first.shop, second.shop));
                console.log(Object.is(first.shop.cart, second.shop.cart));

                Choose an answer to see the explanation.

              4. Question 4 of 7On the compiled page, Review ran for the h, but Stars didn't. Why?

                Choose an answer to see the explanation.

              5. Question 5 of 7Why couldn't memo or the compiler help the highlight page?

                Choose an answer to see the explanation.

              6. Question 6 of 7What did useDeferredValue change on the highlight page?

                Choose an answer to see the explanation.

              7. Question 7 of 7What does the Profiler's baseDuration tell you?

                Choose an answer to see the explanation.

              Key takeaways

              • A component runs again when its state changes, its parent renders, or a context it reads changes.
              • On the naive page, one letter ran 6,306 components to change a few things. Much of a slow key can be work that changes nothing.
              • memo skips a component only if every prop is the same object. Keep functions and objects the same with useCallback and useMemo.
              • The React Compiler adds that memoization for you, from plain code. Here it matched careful memo by hand.
              • When every part really changes, nothing can be skipped. A deferred value or a transition lets the box go first.
              • A transition can't split React's commit or the browser's layout. It also keeps shown content from hiding behind a fallback.
              • Find what ran with the Profiler, React DevTools and React's tracks, in the profiling build. Quote INP from production.

              Remember the one-liner.
              Find who ran, skip what didn't change, and let what must change wait.

              Sources

              The facts on this page come from these docs and source files:

              Coming next: Next.js performance. The same ideas, inside the framework built on React: its images, fonts and scripts, its caching, and its server components.

              CompleteFrontend Clear concepts. Working examples.