A performance profiling tool for React applications that provides detailed insights into component render times, wasted renders, and DOM operations
npx @tessl/cli install tessl/npm-react-addons-perf@15.4.0React Addons Perf is a performance profiling tool for React applications that provides detailed insights into component render times, wasted renders, and DOM operations. It helps developers identify performance bottlenecks and optimization opportunities by measuring and analyzing React component behavior during development.
npm install react-addons-perfimport Perf from 'react-addons-perf';For CommonJS:
var Perf = require('react-addons-perf');For React with addons bundle:
var Perf = React.addons.Perf;import Perf from 'react-addons-perf';
// Start profiling
Perf.start();
// Perform React operations (renders, updates, etc.)
// ... your app code here ...
// Stop profiling
Perf.stop();
// View results
Perf.printWasted(); // Most useful - shows wasted renders
Perf.printInclusive(); // Shows inclusive render times
Perf.printExclusive(); // Shows exclusive render times
Perf.printOperations(); // Shows DOM operationsReact Addons Perf integrates with React's development build to collect performance measurements:
ReactDebugTool API to capture timing data during component lifecycle eventsstart() and stop() calls, storing measurements in flushHistoryrender, componentDidMount, etc.) to measure execution timeconsole.table() for easy analysisControl when performance measurements are collected.
/**
* Start performance measurement session
* No-op in production builds
*/
function start(): void;
/**
* Stop performance measurement session
* No-op in production builds
*/
function stop(): void;
/**
* Check if profiler is currently running
* @returns false in production builds
*/
function isRunning(): boolean;Access raw and processed performance measurement data.
/**
* Get measurement data from last profiling session
* @returns Array of HistoryItem objects containing measurements, operations, and tree snapshots. Empty array in production builds.
*/
function getLastMeasurements(): FlushHistory;
/**
* Calculate exclusive render times (excluding child components)
* @param flushHistory - Optional measurement data, defaults to getLastMeasurements()
* @returns Array of exclusive time statistics
*/
function getExclusive(flushHistory?: FlushHistory): ExclusiveStats[];
/**
* Calculate inclusive render times (including child components)
* @param flushHistory - Optional measurement data, defaults to getLastMeasurements()
* @returns Array of inclusive time statistics
*/
function getInclusive(flushHistory?: FlushHistory): InclusiveStats[];
/**
* Identify components that rendered without DOM changes (wasted renders)
* @param flushHistory - Optional measurement data, defaults to getLastMeasurements()
* @returns Array of wasted render statistics
*/
function getWasted(flushHistory?: FlushHistory): WastedStats[];
/**
* Get DOM operations performed during measurement
* @param flushHistory - Optional measurement data, defaults to getLastMeasurements()
* @returns Array of DOM operation records
*/
function getOperations(flushHistory?: FlushHistory): OperationStats[];Display formatted performance data in the browser console.
/**
* Print exclusive render times to console table
* @param flushHistory - Optional measurement data
*/
function printExclusive(flushHistory?: FlushHistory): void;
/**
* Print inclusive render times to console table
* @param flushHistory - Optional measurement data
*/
function printInclusive(flushHistory?: FlushHistory): void;
/**
* Print wasted render analysis to console table
* @param flushHistory - Optional measurement data
*/
function printWasted(flushHistory?: FlushHistory): void;
/**
* Print DOM operations to console table
* @param flushHistory - Optional measurement data
*/
function printOperations(flushHistory?: FlushHistory): void;Legacy methods maintained for backwards compatibility.
/**
* @deprecated Use printOperations() instead
* Print DOM operations to console table
*/
function printDOM(measurements: FlushHistory): void;
/**
* @deprecated Use getWasted() instead
* Get wasted render statistics
*/
function getMeasurementsSummaryMap(measurements: FlushHistory): WastedStats[];// Core measurement data structure
type FlushHistory = HistoryItem[];
type DebugID = number;
interface HistoryItem {
duration: number;
measurements: Measurement[];
operations: Operation[];
treeSnapshot: TreeSnapshot;
}
interface Measurement {
timerType: TimerType;
instanceID: DebugID;
duration: number;
}
type TimerType =
| 'ctor'
| 'render'
| 'componentWillMount'
| 'componentWillUnmount'
| 'componentWillReceiveProps'
| 'shouldComponentUpdate'
| 'componentWillUpdate'
| 'componentDidUpdate'
| 'componentDidMount';
interface TreeSnapshot {
[key: DebugID]: {
displayName: string;
text: string;
updateCount: number;
childIDs: DebugID[];
ownerID: DebugID;
parentID: DebugID;
};
}
interface Operation {
instanceID: DebugID;
type: string;
payload: any;
}
// Statistics returned by get* methods
interface ExclusiveStats {
key: string;
instanceCount: number;
counts: { [timerType: string]: number };
durations: { [timerType: string]: number };
totalDuration: number;
}
interface InclusiveStats {
key: string;
instanceCount: number;
inclusiveRenderDuration: number;
renderCount: number;
}
interface WastedStats {
key: string;
instanceCount: number;
inclusiveRenderDuration: number;
renderCount: number;
}
interface OperationStats {
flushIndex: number;
instanceID: DebugID;
key: string;
type: string;
ownerID: DebugID;
payload: any;
}import Perf from 'react-addons-perf';
// Start measurement
Perf.start();
// Trigger React renders
ReactDOM.render(<MyApp />, container);
// Stop measurement
Perf.stop();
// Analyze results - most useful first
Perf.printWasted(); // Identify unnecessary re-renders
Perf.printInclusive(); // See total render times including children
Perf.printExclusive(); // See render times excluding children
Perf.printOperations(); // See actual DOM changesimport Perf from 'react-addons-perf';
// Collect measurements
Perf.start();
// ... React operations ...
Perf.stop();
// Get raw data for custom analysis
const measurements = Perf.getLastMeasurements();
const wasted = Perf.getWasted(measurements);
// Find components with most wasted time
const topWasted = wasted
.sort((a, b) => b.inclusiveRenderDuration - a.inclusiveRenderDuration)
.slice(0, 5);
console.log('Top 5 components with wasted renders:', topWasted);import Perf from 'react-addons-perf';
// First session
Perf.start();
// ... first set of operations ...
Perf.stop();
const firstSession = Perf.getLastMeasurements();
// Second session
Perf.start();
// ... second set of operations ...
Perf.stop();
const secondSession = Perf.getLastMeasurements();
// Compare sessions
console.log('First session wasted:', Perf.getWasted(firstSession));
console.log('Second session wasted:', Perf.getWasted(secondSession));React Addons Perf only works in development builds of React. In production builds:
false, [], undefined)The profiler itself introduces some performance overhead during measurement. Use it only when actively debugging performance issues, not in production.
The print* methods use console.table() to display formatted results. Ensure your browser's developer tools are open to see the output.
printWasted() and getWasted() are typically the most useful methods as they identify components that re-rendered without producing DOM changes - the primary optimization target for React applications.