Locate expensive subtrees
Diagnosing slow updates
React 19+ · Component
<Profiler> measures a React subtree’s rendering performance programmatically. Give it an id and an onRender callback to receive information about committed updates and their timing.
Wrap a React subtree in Profiler and provide an identifier plus an onRender callback. React invokes the callback after updates commit, supplying timing and render metadata so you can inspect costly subtrees.
<Profiler id="name" onRender={callback}>{children}</Profiler>| Name | Type | Description |
|---|---|---|
id | string | String identifying the UI portion being measured. |
onRender | function | Callback invoked when components within the profiled tree update; it receives render and timing information. |
A React element that renders its children while reporting profiled commits through onRender.
import { Profiler, useState } from 'react';
function onRender(id: string, phase: string, actualDuration: number) {
console.log(`${id}: ${phase}, ${actualDuration.toFixed(1)}ms`);
}
export default function App() {
const [count, setCount] = useState(0);
return (
<Profiler id="Counter" onRender={onRender}>
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
</Profiler>
);
}Wrap the subtree to measure and log each committed render.
Diagnosing slow updates
Comparing application regions
Investigating production performance
Profiler measures a React tree programmatically. It requires an id and an onRender callback, which React calls when a component in the profiled tree commits an update.
Follow-up: How would you isolate performance problems across a large app? Add multiple Profiler boundaries around the areas you want to compare, then inspect each callback’s reported render information.
The id is a string naming the UI region being measured. The callback receives information about what rendered and how long it took.
Follow-up: What trade-off should guide where boundaries are added? Profiling adds CPU and memory overhead, so instrument only the regions needed for diagnosis.
Profiler can be used in production only with a special profiling-enabled production build; ordinary production profiling is disabled by default to avoid overhead.
Follow-up: What should be compared when investigating a production-only slowdown? Measure the relevant subtree in a profiling build, while remembering that profiling itself changes runtime overhead.
<StrictMode><Activity>React Performance tracks