A performance budget is a number somebody agreed to before the work started. Without one, performance conversations are opinions traded between a developer who can see the flame graph and a product manager who can see the roadmap, and the roadmap usually wins. With one, the argument becomes arithmetic: the initial bundle is allowed three hundred kilobytes gzipped, the primary interaction must respond within a hundred milliseconds, and a pull request that pushes either number over the line fails for reasons nobody has to negotiate about.
âĄBudgets belong next to the tests
A budget that lives in a wiki decays within a quarter. A budget that lives in continuous integration as a failing check becomes part of the definition of done, and the conversation moves from whether to pay the cost to which feature gets to spend the allowance.
A budget is a number, not an opinion
Start from the device and network your users actually have, not the laptop on your desk. A mid-range Android phone on a throttled connection takes five to eight times longer than a development machine to parse and execute the same JavaScript, because parsing, compiling and running are all CPU work that scales with the processor. Budgets expressed on that reference device survive contact with reality; budgets expressed on a flagship never do.
The useful budgets are few and blunt. Total bytes for the first load, the number of requests, the largest contentful paint on the reference device, the time from input to next paint for the primary control, and the cumulative layout shift during load. Five numbers, each with an owner, each checked automatically, is more effective than a dashboard of forty metrics nobody reads.
What goes in the budget
The table below is a working starting point for a content-heavy application. Adjust the values to your audience, but keep the structure: every row has a limit, a measurement method and a consequence.
| Budget | Limit | Measured by | Consequence of a breach |
|---|---|---|---|
| Initial JavaScript, gzipped | 170 kB | Bundle analyzer in CI | Pull request fails until a chunk moves out |
| Total first-load weight | 500 kB | Lighthouse on a throttled profile | Feature flagged until reduced |
| Largest contentful paint | 2.5 s | Field data over 28 days | Release review with the owning team |
| Input to next paint | 100 ms | Interaction to next paint | Render path must be profiled and fixed |
| Cumulative layout shift | 0.1 | Field data over 28 days | Skeletons sized to content before merge |
| Time to first byte | 600 ms | Server timing header | Cache or query plan changes required |
Two properties make this list work. Each limit is enforced by a tool rather than by a person reading a chart, and each has a defined response, so a breach starts a known process instead of a debate. Without the response column, a budget is only a wish.
Splitting routes and heavy widgets
Route-level splitting is the highest yield change in most React applications, because a visitor almost never views more than a handful of pages during a session, yet a single bundle makes them download every one of them. The second tier splits by feature: a charting library, a rich text editor or a date picker that only one screen uses should never ride along with the home page.
import { lazy, Suspense, useEffect } from 'react';
import { Routes, Route, NavLink } from 'react-router-dom';
const Home = lazy(() => import('./pages/Home'));
const Reports = lazy(() => import('./pages/Reports'));
const Settings = lazy(() => import('./pages/Settings'));
const ChartEditor = lazy(() => import('./pages/ChartEditor'));
function prefetchOnHover(load) {
let scheduled = false;
return () => {
if (scheduled) return;
scheduled = true;
const idle = window.requestIdleCallback || ((fn) => setTimeout(fn, 200));
idle(() => { load(); scheduled = false; });
};
}
export default function App() {
const prefetchReports = prefetchOnHover(() => import('./pages/Reports'));
useEffect(() => {
const warm = () => import('./pages/Settings');
const idle = window.requestIdleCallback || ((fn) => setTimeout(fn, 1200));
idle(warm);
}, []);
return (
<nav>
<NavLink to="/">Home</NavLink>
<NavLink to="/reports" onMouseEnter={prefetchReports}>Reports</NavLink>
<NavLink to="/settings">Settings</NavLink>
<Suspense fallback={<div className="route-skeleton" role="status">Loading...</div>}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/reports" element={<Reports />} />
<Route path="/settings" element={<Settings />} />
<Route path="/charts/:id" element={<ChartEditor />} />
</Routes>
</Suspense>
</nav>
);
}
The prefetch helpers deserve a note. Hovering a link on a desktop is a reliable signal that the person is about to click, and starting the request then removes the perceived wait entirely. Deferring the idle warm-up past the first second keeps it from competing with the initial render. Neither costs the user anything if they never navigate, which is why prefetch must stay cheap and idempotent.
Profiling render cost before touching memo
Premature memoization is the performance equivalent of a premature index: it costs correctness risk and mental overhead, and it frequently does nothing. Measure first. The React DevTools profiler records which components rendered during a commit, why they rendered, and how long the commit took, which turns "the list feels slow" into "this row component re-renders on every keystroke in the filter box."
import { Profiler, useState } from 'react';
const marks = [];
function onRender(id, phase, actualDuration) {
marks.push({ id, phase, actualDuration, at: performance.now() });
if (marks.length > 200) marks.shift();
}
export function measureReport(label) {
const durations = marks
.filter((m) => m.id.startsWith(label))
.map((m) => m.actualDuration);
const total = durations.reduce((sum, d) => sum + d, 0);
const worst = Math.max(...durations, 0);
return { count: durations.length, total, worst };
}
export default function Dashboard({ rows }) {
const [filter, setFilter] = useState('');
return (
<Profiler id="dashboard" onRender={onRender}>
<input
value={filter}
onChange={(e) => setFilter(e.target.value)}
aria-label="Filter rows"
/>
<VirtualTable rows={rows} filter={filter} />
</Profiler>
);
}
Read the results in order: find the commit with the longest duration, see which components rendered in it, then ask why each one rendered. Common answers are a new object or function created inline and passed as a prop, a context value that changes on every provider render, or state that belongs in a component further down the tree. Fix the cause rather than wrapping the component in memo, because memo only hides the symptom while the prop keeps being recreated.
Enforcing the budget in continuous integration
The enforcement layer is small and worth building once. Run the bundle analyzer and assert that no entry chunk exceeds the limit, run Lighthouse against the built output on a throttled profile and assert the budgeted metrics, and post the delta against the base branch as a comment on the pull request so reviewers see the cost of the change next to its code.
Keep a baseline file with the current numbers and require an explicit update when a breach is intentional. That single rule converts performance from a recurring argument into a recorded decision: someone edits the baseline, the diff shows the new allowance, and the trade-off is visible in review forever after.
Optimizations that rarely pay for themselves
Not every technique earns its complexity. Virtualizing a list of twelve rows adds scroll measurement, focus restoration bugs and a hard-to-reproduce jump at the boundary. Splitting a component that is thirty lines and always rendered buys nothing but an extra request. Global state libraries introduced for a single value add a layer that every new developer must learn before contributing.
The pattern is to apply the heaviest tool only after the cheap ones are exhausted: fix prop identity first, move state closer to where it is used second, memoize the genuinely expensive subtree third, and reach for virtualization or worker offloading only when a measurement still shows the budget is at risk. Each step up that ladder costs more in complexity than the one before it, so the order matters as much as the choice.
Common Mistakes
Setting a performance goal without naming a device, a network profile and a number
Fix: Pick a reference device and network, write the limit in the budget table, and measure against that profile every time.
Wrapping components in memo before recording which component is actually slow
Fix: Profile the interaction, find the commit that overran, and fix the prop or context that caused the re-render.
Letting a bundle analyzer report exist without a failing check attached to it
Fix: Assert size limits in continuous integration so a breach blocks the merge instead of appearing in a dashboard.
Treating lab scores as proof that the product is fast
Fix: Watch field data for the interaction that matters, because real devices and networks dominate the experience.
Best Practices
- Write five budgets with an owner and a consequence, and delete metrics nobody acts on
- Split at route boundaries first and at heavy feature boundaries second, prefetching on hover so the speed is invisible
- Profile before optimizing and fix the cause of a re-render rather than masking it with memo
- Keep a baseline file in the repository so a performance change is an explicit, reviewable edit
Key Takeaways
- A budget is a limit, a measurement method and a defined consequence, agreed before the feature starts
- Route and feature splitting remove code most sessions never need, and hover or idle prefetch hides the remaining latency
- The profiler shows which components rendered and why, which is how you fix re-renders instead of decorating them
- Enforcement in continuous integration with a reviewable baseline turns performance debates into recorded decisions
- Expensive tools pay off only after prop identity, state placement and memoization of real hot paths have been addressed