The React Performance Engineer diagnoses and fixes slow React applications. The most common cause of sluggish UIs is not algorithm complexity - it is unnecessary component re-renders caused by unstable prop references and poor state placement. Profile first with React DevTools; optimise only what the profiler shows is slow.
Re-render Diagnosis
// Install React DevTools, open Profiler tab, record an interaction
// Click "Highlight updates" to see what's re-rendering
// Common causes:
// 1. New object/array literal created on every parent render
const Parent = () => {
// ❌ New array on every render - causes Child to re-render even if data unchanged
return <Child items={[1, 2, 3]} />;
// ✅ Move constant outside component or useMemo
};
// 2. Inline function creates new reference on every render
const Parent = () => {
// ❌ New function on every render
return <Button onClick={() => doSomething()} />;
// ✅ useCallback for stable reference when child is memoized
const handleClick = useCallback(() => doSomething(), []);
return <Button onClick={handleClick} />;
};
Memoization Patterns
// memo - skip re-render when props are shallowly equal
const ExpensiveList = React.memo(({ items }: { items: Item[] }) => {
return <ul>{items.map(item => <li key={item.id}>{item.name}</li>)}</ul>;
});
// useMemo - cache expensive computations
const sortedItems = useMemo(() =>
[...items].sort((a, b) => a.name.localeCompare(b.name)),
[items] // Only re-sort when items array changes
);
// useCallback - stable function references for memoized children
const handleDelete = useCallback((id: string) => {
setItems(prev => prev.filter(item => item.id !== id));
}, []); // Empty deps - setItems from useState is stable
// Rules:
// - Measure before adding memo/useMemo - they add overhead for simple components
// - memo is only effective if ALL props are stable (use with useCallback/useMemo on parents)
// - Prefer state co-location over memoization - move state down to where it's used
List Virtualization
import { FixedSizeList } from 'react-window';
// Render 10,000 items - only DOM nodes for visible rows are created
const VirtualList = ({ items }: { items: Item[] }) => {
const Row = ({ index, style }: { index: number; style: React.CSSProperties }) => (
<div style={style}>{items[index].name}</div>
);
return (
<FixedSizeList height={600} itemCount={items.length} itemSize={48} width="100%">
{Row}
</FixedSizeList>
);
};
// Use react-window for lists with >100 items, react-virtual for variable-height rows
Bundle Optimization
- Run
npx vite-bundle-visualizerorwebpack-bundle-analyzerto find large dependencies - Route-based code splitting:
const Page = lazy(() => import('./pages/Page'))- each route loads its own chunk - Replace moment.js (65kb) with date-fns (tree-shakeable, pay-per-function)
- Import specific lodash functions:
import debounce from 'lodash/debounce'notimport _ from 'lodash' - Target <200kb initial JS bundle for good LCP scores