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.
- 01Find what ran, and whyCount the components one key press runs, and name each one's reason: its own state, its parent, or a context.
- 02Skip what didn't changeUse memo with useMemo and useCallback, or the React Compiler, and say what each leaves for the browser to do.
- 03Let 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:
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:
// 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 msandmemo only: 103.6 ms. - Then
memo, useMemo and useCallback: 56.9 msandThe React Compiler: 59.2 ms. - Last,
Highlighting the word: 308.2 msandHighlighting, 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.
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
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:
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:
queryis the box's text,cartcounts the cart, andvoteslists 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
shopto 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
setQuerywith 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:
// 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.andReview 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
querychanged. - 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
shopobject 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.
- Appran 1 time
- · Headerran 1 time
- · · CartBadgeran 1 time
- · AddButtonran 1 time
- · FilterBoxran 1 time
- · ReviewListran 1 time
- · · Reviewran 900 times
- · · · Starsran 900 times
- · · · · Starran 4,500 times
- h: 6,306 components ranrender 44.9 ms, key 97.3 ms
- o: 2,456 components ranrender 17.5 ms, key 61.2 ms
- n: 1,756 components ranrender 11.3 ms, key 36.2 ms
- e: 1,756 components ranrender 9.6 ms, key 21.3 ms
- y: 1,406 components ranrender 9.6 ms, key 27.2 ms
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.
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:
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:
// 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?
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:
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
renderruns. - 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 printsfalse: 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:
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:
useMemokeeps the filtered list untilquerychanges. React's docs say it caches "the result of a calculation between re-renders." - Line 2:
useCallbackkeeps the sameaddToCartfunction. The empty list at the end says nothing it uses can change. - Line 3 keeps the same
shopobject until the cart changes. - Line 4 keeps the same
markHelpful. It passes a function tosetVotes, 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:
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.
_ccomes fromreact/compiler-runtime, which calls React'suseMemoCache(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.
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
// 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.
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.
useMemoanduseCallbackstill 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:
<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.
// 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, toy: 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:
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 realquery.
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.
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 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 msandThe 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:
- h, pressed at 0.0 mstook 308.2 ms
- waited 0.8 mslist for "h" put on the page at 120.2 ms
- o, pressed at 117.7 mstook 190.5 ms
- waited 73.2 mslist for "ho" put on the page at 251.2 ms
- n, pressed at 238.6 mstook 195.1 ms
- waited 61.3 mslist for "hon" put on the page at 338.8 ms
- e, pressed at 357.4 mstook 76.3 ms
- waited 18.8 mslist for "hone" put on the page at 404.0 ms
- y, pressed at 476.6 mstook 58.3 ms
- waited 3.0 mslist for "honey" put on the page at 507.4 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.
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:
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.
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:
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 importsonRender, the course's function that keeps each report. - Lines 7 to 9 wrap App in it.
idnames the part of the page being measured. - React calls
onRenderwith the id, the phase and four times. Two of them matter here.actualDurationis how long this render took.baseDurationis about how long rendering the whole tree again would take, from each component's last render.
// 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:
// 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.
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:
- Blocking: Event: input3.6 ms, from 4.8 ms
- Blocking: Update0.2 ms, from 8.4 ms
- Blocking: Render52.3 ms, from 8.6 ms
- Blocking: Commit19.5 ms, from 60.9 ms
- Blocking: Waiting0.0 ms, from 80.4 ms
- Blocking: Remaining Effects24.2 ms, from 80.4 ms
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.
Which tool for which slow interaction?
Read this table across. Each row is one page, and what Asha's h cost on it.
| Page | What changed | What ran for the h | React's render for the h | The slowest key |
|---|---|---|---|---|
| As Ravi wrote it | Nothing: App keeps all the state. | 6,306 components, 900 of them Review. | 44.9 ms. | 97.3 ms, on the h. |
| memo only | memo 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 useCallback | memo, 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 Compiler | The naive code, run through the React Compiler. | 903 components, 900 of them Review. | 11.4 ms. | 59.2 ms, on the h. |
| Highlighting the word | The 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 useDeferredValue | The 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:
- 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
Sort each slow spot by what can help it.
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.
memo compares each prop with Object.is. Which props of this review does it see as changed?
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");onHelpful. The arrow on line 3 is a new function, even though it only calls markHelpful. memo would run the review again. useCallback, or the compiler, keeps the same function.
These are the memo page's two Profiler times for the h. What does it print?
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.`);React skipped about 93% of the tree's cost. actualDuration is what this render took. baseDuration is about what rendering everything again would take. The gap is what memo saved.
On the compiled page, how many components ran for Asha's o?
353: App, FilterBox, ReviewList and 350 Reviews. Each Review returned its saved element, so no Stars ran. 350 reviews mention ho.
On the highlight page, how long did the n wait before its handlers could start, in ms?
61.3 ms. The n waited behind the o's work: React marking 350 reviews, then the browser's work on them. Every key after a slow one pays some of its cost.
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?
Update Blocked. React names the gap between an update and its render that way when it's longer than 5 ms (ReactFiberPerformanceTrack.js, line 752). The o's update waited for the list's work to finish.
React's docs say how often, at most, React reveals content that was waiting in a Suspense boundary. Once every how many ms?
300 ms. React reveals suspended content at most once every 300 ms, from the last reveal. Boundaries that become ready inside that time appear together.
Check your understanding
For each question, ask two things: did the component's output really change, and could the work wait?
Question 1 of 7In React's docs, what does "rendering" mean?
Choose an answer to see the explanation.
Question 2 of 7On the memo-only page, why did every review still run for the h?
Choose an answer to see the explanation.
Question 3 of 7What does this Object.is example print on its third line?
Read the code, then predictfunction 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.
Question 4 of 7On the compiled page, Review ran for the h, but Stars didn't. Why?
Choose an answer to see the explanation.
Question 5 of 7Why couldn't memo or the compiler help the highlight page?
Choose an answer to see the explanation.
Question 6 of 7What did useDeferredValue change on the highlight page?
Choose an answer to see the explanation.
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:
- Render and Commit, React.
- ReactFiberBeginWork.js, React 19.3.1, React source.
- memo, React.
- useMemo, React.
- useCallback, React.
- shallowEqual.js, React 19.3.1, React source.
- ReactFiberNewContext.js, React 19.3.1, React source.
- React Compiler: Introduction, React.
- React Compiler: Installation, React.
- React Compiler v1.0, React blog.
- babel-plugin-react-compiler, npm.
- ReactFiberHooks.js, React 19.3.1, React source.
- useDeferredValue, React.
- useTransition, React.
- <Suspense>, React.
- <Profiler>, React.
- React Performance tracks, React.
- Introducing the React Profiler, React blog.
- ProfilerSettings.js, React DevTools in React 19.3.1, React source.
- WhatChanged.js, React DevTools in React 19.3.1, React source.
- GeneralSettings.js, React DevTools in React 19.3.1, React source.
- ReactFiberPerformanceTrack.js, React 19.3.1, React source.
- ReactFiberCommitWork.js, React 19.3.1, React source.
- Customize your performance data with extensibility APIs, Chrome for Developers.
- Interaction to Next Paint (INP), web.dev.
- Performance: now() method, MDN.
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.