A page that scores well in a lab and a page that feels fast to a customer are two related but different claims, and the gap between them is where most performance work quietly dies. Lab measurements are taken once, on one machine, on one connection, under conditions you chose. Field measurements are the aggregate of what actually happened on whatever phones, networks and cache states your users brought with them. Performance monitoring is the discipline of collecting the second, using the first to reproduce what the second revealed, and keeping a budget strict enough that slow code cannot merge in the first place. This lesson wires real user measurement into a React application, profiles a render before anyone is allowed to optimise it, and defines the small set of gates that stop the numbers from drifting back.
âĄMeasure the seventy-fifth percentile
Averages hide the users you are losing. Report the seventy-fifth percentile for every vital, segmented by device class and route, because a smooth experience on a flagship phone and a five second stall on a mid-range Android are invisible to each other in a single mean.
Lab numbers and field numbers disagree
Core Web Vitals are field metrics with published thresholds, and each one has a small number of causes you can actually act on inside a React codebase. The table below is the working reference: what the metric captures, where the line between acceptable and poor sits, and which lever usually moves it.
| Metric | What it captures | Good | Poor | Main lever in React |
|---|---|---|---|---|
| Largest Contentful Paint | When the main content appears | 2.5 s or better | Over 4 s | Server response, image priority, route splitting |
| Interaction to Next Paint | Delay before the next frame after input | 200 ms or better | Over 500 ms | Long tasks, expensive effects, update storms |
| Cumulative Layout Shift | Unintended movement during load | 0.1 or better | Over 0.25 | Reserved space for media and async content |
| First Contentful Paint | First pixel of rendered content | 1.8 s or better | Over 3 s | Render-blocking CSS, blocking fonts |
| Time to First Byte | Latency of the first response byte | 800 ms or better | Over 1.8 s | Edge caching, origin work, per-request rendering |
Lab tools such as Lighthouse remain indispensable for diagnosis, because they give you a flame graph and a deterministic run. What they cannot give you is a distribution. A page that is fast on a datacentre machine with a warm cache and slow on the hardware your audience actually owns will pass every lab test you write, which is why a performance review that ends with a lab score is only half complete.
Sending Web Vitals from real sessions
The browser exposes the timings you need through PerformanceObserver, and the web-vitals package normalises the edge cases across browsers and versions. The integration has three decisions worth making deliberately: when to send, what to attach, and how much to keep.
Send on page hide rather than on unload, because unload handlers do not fire reliably during a navigation and a beacon issued at the right moment survives the transition. Attach the route, the release identifier and the connection class, otherwise a spike cannot be attributed to anything. Keep the payload small and sample if traffic is heavy, because the metric you care about is a percentile and a fraction of sessions is enough to compute one, provided the sampling is random rather than biased toward fast devices.
// src/reportWebVitals.js
import { onCLS, onINP, onLCP, onTTFB } from 'web-vitals';
function buildPayload(metric) {
return JSON.stringify({
name: metric.name,
value: metric.value,
rating: metric.rating,
navigationType: metric.navigationType,
route: window.location.pathname,
release: window.__RELEASE__,
device: navigator.deviceMemory ? 'low-memory' : 'standard',
});
}
function send(metric) {
const body = buildPayload(metric);
if (navigator.sendBeacon) {
navigator.sendBeacon('/api/vitals', body);
} else {
fetch('/api/vitals', { method: 'POST', body, keepalive: true });
}
}
export function initWebVitals() {
onLCP(send, { reportAllChanges: false });
onINP(send);
onCLS(send);
onTTFB(send);
}
Call that once from the application entry point, then aggregate on the server: count sessions rather than events, bucket by release and route, and alert when the seventy-fifth percentile of the primary interaction metric crosses the threshold for two consecutive releases. Strip anything user specific before storage, because a route identifier is telemetry and a query string containing an account number is not.
Profiling renders with the React Profiler
Once field data tells you a route is slow, the profiler tells you why. React ships a Profiler component that reports how long a commit took and which subtree was responsible, and the browser profiling tab shows the long tasks between commits. The mistake to avoid is reaching for memoisation before either tool has been opened, because optimising a render you have not measured usually trades a real cost for a speculative one.
import { Profiler, useState } from 'react';
function onRender(id, phase, actualDuration, baseDuration) {
if (actualDuration > 16) {
console.info(id, phase, {
actual: Math.round(actualDuration),
hypotheticalWithoutMemo: Math.round(baseDuration),
});
}
}
export function Dashboard() {
const [range, setRange] = useState('7d');
return (
<Profiler id="Dashboard" onRender={onRender}>
<RangePicker value={range} onChange={setRange} />
<RevenueChart range={range} />
<ActivityFeed range={range} />
</Profiler>
);
}
Read the two durations as a comparison rather than as absolutes. Actual duration is what this commit cost, base duration is what it would have cost without any memoisation, and the difference tells you whether memoisation is even the right lever. Measure in development or a profiling build, because the timing overhead is stripped from the production bundle, and wrap subtrees rather than the entire application so the report points at a component instead of at everything at once.
Budgets that fail the build
Monitoring without a gate is a dashboard that people stop opening. A budget converts a number into a policy: if the initial script exceeds the agreed size, or a lab metric regresses beyond the threshold, the pipeline fails and the conversation happens before the change ships rather than a week afterwards.
| Gate | Enforced by | Threshold to start from | Consequence of a breach |
|---|---|---|---|
| Initial JavaScript, gzipped | Size limit in continuous integration | 170 kB | Build fails until a chunk moves out of the entry |
| Largest Contentful Paint, lab | Lighthouse continuous integration | 2.5 s on a throttled run | Build fails and the diff is attached to the run |
| Interaction latency, field | Alert on the p75 across releases | 200 ms | Page the owning team, block the next rollout |
| Layout shift, field | Alert on the p75 across releases | 0.1 | Open a fix before the next feature release |
| Route level bundle growth | Bundle visualiser in the report | 10 percent per route | Review required from the owning team |
Budgets only hold when they live in the pipeline rather than in a document, and when each one has an owner. A number with no owner becomes a suggestion, and suggestions lose to deadlines every single time.
Watch the journey, not just the page
Single page applications make the pageview an unreliable unit. The load event fires once, while the interactions that dominate perceived speed happen later: opening a menu, filtering a table, submitting a form, navigating between tabs. Instrument those as named interactions rather than lumping them together, and the report starts to read like a product description instead of a server log.
Segmentation does the rest of the work. Compare device classes and connection types, because a regression that only appears on low memory devices will never show up on the machines where the team works. Compare routes, because a dashboard full of charts and a marketing page have completely different bottlenecks. Compare releases, because the most valuable alert you can own is the one that says the last deploy moved the number. Finally, trace third-party scripts separately; a tag manager widget that adds four hundred kilobytes of main thread work is a vendor decision, not an optimisation opportunity, and it needs to appear in the report under its own name.
Turning measurements into fixes
Numbers become useful only when they arrive with a reproduction. Take the slowest route on the slowest device class, reproduce it with CPU throttling and network throttling applied, and open a flame graph before changing code. The recurring patterns are worth knowing by heart: a route that ships its entire dependency tree in the entry chunk wants to be split; a list of ten thousand rows wants virtualisation; an effect that fetches on every keystroke wants debounce or a query library with caching; images without reserved space want explicit dimensions; and a context value rebuilt on every render wants a stable reference or a narrower provider.
Change one thing, re-measure, and record both numbers. Keep a short performance log in the pull request so the next reader sees the before and after rather than a claim. Resist memoisation and micro-optimisation until a profile shows the cost, and prefer the structural fix of shipping fewer bytes and doing less work per frame over the local fix of making one expensive function marginally cheaper.
Common Mistakes
Shipping a lab score to a stakeholder and declaring the page fast
Fix: Treat the lab run as diagnosis and the field distribution as the verdict, segmented by route and device class.
Instrumenting pageviews only and missing the interactions that dominate perceived speed
Fix: Measure named interactions such as menu open, filter and submit, and report their seventy-fifth percentile.
Reaching for memoisation before opening a profile
Fix: Capture a commit trace first, compare actual against base duration, and only memoise where the flame graph shows real cost.
Collecting metrics with no threshold attached
Fix: Give every metric a budget in the pipeline with an owner and a consequence, or the number becomes a decoration.
Shipping telemetry that carries user specific query strings
Fix: Reduce payloads to route, release, rating and connection class before anything is stored or exported.
Best Practices
- Send beacons on page hide with sendBeacon so navigations do not swallow the last measurement
- Attach a release identifier to every metric so a regression can be tied to the deploy that caused it
- Wrap meaningful subtrees in the Profiler rather than the whole app, so reports name a component instead of everything
- Keep budgets in continuous integration with owners, and review bundle growth per route in every pull request
- Measure on reference hardware with throttling, then confirm on real users, in that order for every optimisation
Key Takeaways
- Field data gives the distribution and the verdict; lab data gives the reproduction and the flame graph
- Report the seventy-fifth percentile by route, device and release, because averages hide the users who are actually blocked
- Web Vitals integration is three decisions: send on page hide, attach route and release, and sample rather than store everything
- The Profiler compares actual against hypothetical cost, which is how you learn whether memoisation is the right lever
- A budget with an owner and a failing build is a policy; the same number in a document is a suggestion