React DevTools Profiler — a tool for measuring rendering performance of components.
Why it matters: Optimizing without measurement is guessing. The Profiler shows exactly which components re-render, how long each render takes, and why. This data-driven approach prevents premature optimization (wrapping everything in React.memo) and targets the actual bottlenecks.
How to use:
What it shows:
What to look for:
Programmatic approach (React.Profiler):
1import { Profiler } from "react";23function onRenderCallback(id, phase, actualDuration) {4 if (actualDuration > 16) { // More than 16ms = 60fps5 console.warn(`Slow render: ${id} — ${actualDuration}ms`);6 }7}89<Profiler id="ExpensiveList" onRender={onRenderCallback}>10 <ExpensiveList items={items} />11</Profiler>
Advanced profiling pattern — collecting metrics over time:
1const renderMetrics: Record<string, number[]> = {};23function trackRender(id: string, phase: string, actualDuration: number) {4 if (!renderMetrics[id]) renderMetrics[id] = [];5 renderMetrics[id].push(actualDuration);6 const avg = renderMetrics[id].reduce((a, b) => a + b, 0) / renderMetrics[id].length;7 if (avg > 10) console.warn(`${id} avg: ${avg.toFixed(1)}ms (${renderMetrics[id].length} renders)`);8}910<Profiler id="Dashboard" onRender={trackRender.bind(null, "Dashboard")}>11 <Dashboard />12</Profiler>
Optimization tips: