React Performance Optimization: From Slow to Lightning Fast
Source: Dev.to
Profile First — Don’t Guess
Use the React DevTools Profiler to find the actual bottleneck:
- Open the Profiler tab.
- Record an interaction.
- Examine which components re‑rendered and why.
Memoization
Component Memoization
import { memo } from "react";
const ExpensiveChart = memo(function ExpensiveChart({
data,
width,
height,
}: ChartProps) {
// Only re‑renders when props actually change
return ;
});
Value Memoization
import { useMemo } from "react";
const summary = useMemo(() => ({
total: transactions.reduce((sum, t) => sum + t.amount, 0),
byCategory: groupBy(transactions, "category"),
}), [transactions]);
Note: React 19 introduces automatic memoization at build time, making manual
memo/useMemo/useCallbacklargely unnecessary for new code. Enable it with the experimental compiler flag:{ reactCompiler: true }.
Code Splitting & Lazy Loading
import { lazy, Suspense } from "react";
const DataViz = lazy(() => import("./DataVisualization"));
function Dashboard() {
return (
}>
);
}
Virtualize Long Lists
Render only visible items. For lists with 100+ items, use @tanstack/react-virtual. The overhead of the virtualizer is negligible compared to rendering thousands of DOM nodes.
State Management
The most impactful technique is to put state as close as possible to where it’s used. Frequently changing global state forces the entire tree to re‑render.
Additional Optimizations
- Code‑split heavy routes to reduce initial bundle size.
- Optimize images with
next/imageor lazy loading. - Defer non‑urgent updates using
useDeferredValue. - Enable the React Compiler (React 19) for automatic optimizations.
- Focus on architecture (where state lives, how data flows) rather than micro‑optimizations; a well‑structured app is fast by default.
Quick Checklist
- Profile first — don’t guess.
- Co‑locate state — move it down the tree.
- Virtualize long lists (100+ items).
- Code‑split heavy routes.
- Optimize images (
next/imageor lazy loading). - Defer non‑urgent updates (
useDeferredValue). - Enable React Compiler in React 19.
- Prioritize architecture over micro‑optimizations.
Explore 85+ free developer tools or support this work.