Skip to content

React performance: re-renders, memo and the Compiler

React is fast for most screens without any tuning. Performance work starts when a real interaction feels slow: typing lags in a filter box, a dashboard freezes when a tab opens, the first load downloads megabytes of JavaScript. This page explains what makes React render, then the tools in the order you should reach for them: measuring, structuring state, memoization, the React Compiler, code splitting, transitions and virtualized lists. The running example is OrdersPortal’s order dashboard with 1,000 orders.

The measured samples target React 19.3 and React Compiler 1.0 (babel-plugin-react-compiler, released October 2025). They were bundled with esbuild, rendered into a jsdom document in Node.js 22 and driven by the driver at the end of each sample; the render counts are printed below. Counting renders with a module-level object is a test-only trick: it is a side effect during render, which production components must not have.

Topic Use it to
Re-renders Know what triggers a render and how to measure the cost.
Memoization Skip work with memo, useMemo and useCallback by hand.
React Compiler Get the same memoization automatically at build time.
Code splitting Download code for a screen only when it is needed.
Transitions and long lists Keep typing responsive and render only visible rows.

A component renders when its state changes, when its parent renders, or when a context it reads changes. A parent render re-renders all children by default, whether their props changed or not. Rendering means calling the component function and comparing the result; React then touches the DOM only where the output differs. So most re-renders are cheap, and an “unnecessary” render is a problem only when it is expensive or very frequent, such as a large table re-rendering on every keystroke.

Measure before changing code. The React DevTools Profiler records which components rendered during an interaction, how long each took, and why (“props changed”, “hooks changed”, “parent rendered”). React 19.2 also adds React performance tracks to the browser’s Performance panel in development and profiling builds, showing scheduler and component work on the same timeline as network and layout. Profile a production build when you need real numbers, since development builds are slower.

The cheapest fix is often structural, not memoization: move state down into the component that uses it (a search box that owns its own text), or lift expensive content up and pass it as children, so a parent whose state changes does not re-create it.

Pitfalls:

  • Optimizing without a profile. Memoization has a cost; apply it where the Profiler shows time going.
  • State too high in the tree. Keeping input text in a page-level component re-renders the whole page per keystroke.
  • Measuring in development only. StrictMode double renders and dev checks inflate timings.

Three APIs let you skip work when inputs have not changed, each comparing with Object.is. memo(Component) skips re-rendering a component when all its props are the same as last time. useMemo(fn, deps) caches a computed value, such as a filtered list, between renders. useCallback(fn, deps) caches a function so its identity stays the same, which matters only when the function is passed to a memoized child or used as an effect dependency.

They work together: memo on a child is useless if the parent passes a new array or a new arrow function on every render, because the props are never “the same”. In the dashboard below, typing in the note field re-renders the parent; the unmemoized Summary renders each time, while the memoized OrderTable and the useMemo filter run only when the status filter changes.

import { memo, useCallback, useMemo, useState } from 'react';
const renders = { summary: 0, table: 0, filterRuns: 0 }; // test-only counters
const OrderTable = memo(function OrderTable({ orders, onSelect }) {
renders.table++;
return <ul>{orders.map((o) => <li key={o.id} onClick={() => onSelect(o.id)}>{o.id}</li>)}</ul>;
});
function Summary({ count }) { // not memoized: re-renders with its parent
renders.summary++;
return <p>{count} orders</p>;
}
function OrderDashboard({ allOrders }) {
const [note, setNote] = useState(''); // unrelated state, changes on every keystroke
const [status, setStatus] = useState('open');
const [selected, setSelected] = useState(null);
const visible = useMemo(() => {
renders.filterRuns++;
return allOrders.filter((o) => o.status === status);
}, [allOrders, status]);
const handleSelect = useCallback((id) => setSelected(id), []);
return (
<>
<input aria-label="Note" value={note} onChange={(e) => setNote(e.target.value)} />
<button onClick={() => setStatus(status === 'open' ? 'shipped' : 'open')}>Toggle status</button>
<Summary count={visible.length} />
<OrderTable orders={visible} onSelect={handleSelect} />
{selected && <p>Selected {selected}</p>}
</>
);
}
// Driver: type three characters into the note, then toggle the status filter.
import { act } from 'react';
import { createRoot } from 'react-dom/client';
const allOrders = Array.from({ length: 1000 }, (_, i) => ({ id: 1000 + i, status: i % 3 ? 'open' : 'shipped' }));
const root = createRoot(document.getElementById('root'));
await act(() => root.render(<OrderDashboard allOrders={allOrders} />));
const input = document.querySelector('input');
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
for (const text of ['a', 'ab', 'abc']) {
await act(() => { setValue.call(input, text); input.dispatchEvent(new Event('input', { bubbles: true })); });
}
console.log('after typing:', JSON.stringify(renders));
await act(() => document.querySelector('button').click());
console.log('after toggle:', JSON.stringify(renders));

Output:

after typing: {"summary":4,"table":1,"filterRuns":1}
after toggle: {"summary":5,"table":2,"filterRuns":2}

Three keystrokes caused three extra Summary renders but no extra table renders or filter passes.

Pitfalls:

  • Inline objects and functions defeat memo. style={{ color: 'red' }} or onSelect={() => ...} is a new value every render.
  • Memoizing cheap work. Wrapping every value in useMemo adds comparisons and noise without benefit.
  • Wrong dependency arrays return stale cached values; let the lint rule list them.

React Compiler is a build-time tool, stable since version 1.0 in October 2025, that analyzes components and hooks and inserts fine-grained caching automatically, the equivalent of memo, useMemo and useCallback applied wherever it is safe. It works best with React 19 and also supports React 17 and 18 through a runtime package. Install babel-plugin-react-compiler as a dev dependency and run it first in the Babel pipeline; with Vite and @vitejs/plugin-react 6 or later, add @rolldown/plugin-babel with reactCompilerPreset(). Frameworks such as Next.js and React Router framework mode have a configuration switch.

The compiler relies on the rules of React: pure render functions, immutable props and state, and the rules of hooks. If it finds a violation in a component, it skips that component and leaves it as it was, rather than producing wrong code; eslint-plugin-react-hooks reports these cases. The sample removes every manual memoization from the dashboard and compiles it with babel-plugin-react-compiler 1.0.0.

import { useState } from 'react';
const renders = { summary: 0, table: 0 }; // test-only counters
function OrderTable({ orders, onSelect }) {
renders.table++;
return <ul>{orders.map((o) => <li key={o.id} onClick={() => onSelect(o.id)}>{o.id}</li>)}</ul>;
}
function Summary({ count }) {
renders.summary++;
return <p>{count} orders</p>;
}
function OrderDashboard({ allOrders }) {
const [note, setNote] = useState(''); // unrelated state, changes on every keystroke
const [status, setStatus] = useState('open');
const [selected, setSelected] = useState(null);
// No memo, useMemo or useCallback: the compiler inserts equivalent caching.
const visible = allOrders.filter((o) => o.status === status);
const handleSelect = (id) => setSelected(id);
return (
<>
<input aria-label="Note" value={note} onChange={(e) => setNote(e.target.value)} />
<button onClick={() => setStatus(status === 'open' ? 'shipped' : 'open')}>Toggle status</button>
<Summary count={visible.length} />
<OrderTable orders={visible} onSelect={handleSelect} />
{selected && <p>Selected {selected}</p>}
</>
);
}
// Driver: type three characters into the note, then toggle the status filter.
import { act } from 'react';
import { createRoot } from 'react-dom/client';
const allOrders = Array.from({ length: 1000 }, (_, i) => ({ id: 1000 + i, status: i % 3 ? 'open' : 'shipped' }));
const root = createRoot(document.getElementById('root'));
await act(() => root.render(<OrderDashboard allOrders={allOrders} />));
const input = document.querySelector('input');
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
for (const text of ['a', 'ab', 'abc']) {
await act(() => { setValue.call(input, text); input.dispatchEvent(new Event('input', { bubbles: true })); });
}
console.log('after typing:', JSON.stringify(renders));
await act(() => document.querySelector('button').click());
console.log('after toggle:', JSON.stringify(renders));

Output without the compiler, then compiled:

after typing: {"summary":4,"table":4}
after toggle: {"summary":5,"table":5}
after typing: {"summary":1,"table":1}
after toggle: {"summary":2,"table":2}

The compiled dashboard caches the filtered list, the handler and even the child elements, so neither child renders while typing. It goes further than the hand-written version, which still re-rendered Summary. The two children themselves were skipped by the compiler, because their test counters mutate a module variable during render, which is exactly the kind of rule violation it refuses to compile.

Pitfalls:

  • Code that breaks the rules of React is skipped silently unless you run the lint rules; fix violations to get the benefit.
  • Removing manual memoization blindly. The docs recommend keeping existing useMemo and useCallback until you have tested without them, especially where they control effect dependencies.
  • Expecting it to fix algorithmic costs. Filtering 100,000 rows on every status change is still slow; paginate or virtualize.

Bundle size is often a bigger problem than re-renders: every kilobyte of JavaScript must be downloaded, parsed and executed before the screen is interactive. lazy(() => import('./ReportsPage.jsx')) turns a component into a separate chunk that loads the first time it renders; a <Suspense fallback> boundary shows a placeholder meanwhile. Split by route and by heavy, rarely used features (chart libraries, rich text editors, export dialogs), not by every small component.

// Fragment (not run here): route-level splitting with React Router data mode.
import { lazy, Suspense } from 'react';
const ReportsPage = lazy(() => import('./pages/ReportsPage.jsx')); // separate chunk
export const routes = [
{ path: '/orders', element: <OrdersPage /> },
{
path: '/reports',
element: (
<Suspense fallback={<p>Loading reports...</p>}>
<ReportsPage />
</Suspense>
),
},
];

React Router’s route lazy property and framework mode split per route automatically and load the code in parallel with the route’s data.

Pitfalls:

  • Declaring lazy inside a component creates a new component each render and resets its state; declare it at module level.
  • One giant Suspense boundary blanks the whole page while a small widget loads; place boundaries around the parts that load.
  • Splitting everything creates many small requests; measure the bundle with your bundler’s analyzer first.

Some updates are urgent (the character you just typed) and some are not (re-filtering a 5,000-row list). useDeferredValue(query) returns a copy of a value that lags behind during heavy rendering: the input updates immediately, and the expensive list re-renders with the deferred value in the background, interruptible by the next keystroke. useTransition does the same for state updates you trigger, returning isPending for a subtle loading hint. Since React 19.3, separate transitions render independently, so a slow one no longer holds up unrelated ones.

When a list has thousands of rows, rendering them all is slow no matter how well memoized. Virtualization renders only the rows in view plus a small buffer; TanStack Virtual (@tanstack/react-virtual, version 3) is a headless option.

// Fragment (not run here): deferred filtering plus a virtualized list.
import { useDeferredValue, useRef, useState } from 'react';
import { useVirtualizer } from '@tanstack/react-virtual';
function OrderSearch({ orders }) {
const [query, setQuery] = useState('');
const deferredQuery = useDeferredValue(query); // input stays responsive
const matches = orders.filter((o) => o.customer.includes(deferredQuery));
const isStale = query !== deferredQuery;
const scrollRef = useRef(null);
const rows = useVirtualizer({
count: matches.length,
getScrollElement: () => scrollRef.current,
estimateSize: () => 36, // row height in px
overscan: 8,
});
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} aria-label="Search customer" />
<div ref={scrollRef} style={{ height: 480, overflow: 'auto', opacity: isStale ? 0.6 : 1 }}>
<div style={{ height: rows.getTotalSize(), position: 'relative' }}>
{rows.getVirtualItems().map((row) => (
<div key={matches[row.index].id}
style={{ position: 'absolute', top: 0, width: '100%', transform: `translateY(${row.start}px)` }}>
{matches[row.index].id} {matches[row.index].customer}
</div>
))}
</div>
</div>
</>
);
}

Pitfalls:

  • Deferring without memoizing the slow part. The background render only helps if the expensive child can skip work when the deferred value has not changed (memo or the compiler).
  • Virtualizing small lists adds complexity and breaks browser find-in-page; use it from hundreds or thousands of rows.
  • Transitions for controlled input values. Updating an input’s own state inside startTransition makes typing lag; keep the input urgent and defer the expensive part.
Symptom First thing to try
Typing lags in one field Move state down; then useDeferredValue for the expensive output
A big subtree re-renders for unrelated changes React Compiler, or memo plus stable props
Expensive calculation repeated every render useMemo or the compiler
Slow first load Route-level code splitting with lazy
Thousands of rows Virtualization and pagination
Context change re-renders everything Split or narrow the context

Does a component re-render when its props do not change? Yes, by default it re-renders whenever its parent renders. It skips only if wrapped in memo (or compiled by the React Compiler) and every prop is Object.is-equal to the previous one.

When is useCallback worth using? When the function is passed to a memoized child, used as an effect dependency, or returned from a custom hook whose callers depend on its identity. Otherwise it adds cost without benefit, and with the React Compiler it is rarely needed.

What does the React Compiler do with code that breaks the rules of React? It skips compiling that component or hook and leaves it unoptimized. It does not change behavior, so it is safe to adopt incrementally; the lint rules show which components were skipped and why.

What is the difference between useTransition and useDeferredValue? useTransition marks a state update you trigger as non-urgent and gives you isPending. useDeferredValue defers a value you receive, such as a prop or state, when you do not control the update. Both let urgent updates interrupt the background render.

Senior scenario: the orders dashboard takes 4 seconds to become interactive on mid-range laptops. How do you approach it? Measure first: a production Lighthouse or Performance panel trace separates download and parse time from render time. If the bundle dominates, analyze it, split routes and heavy widgets with lazy, and drop or replace large dependencies. If rendering dominates, profile with React DevTools, virtualize the order table, move filter state down, enable the React Compiler, and move expensive derived data to the server or a paginated API. Set a performance budget in CI so the regression does not return.