🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Monitoring React Performance in Production

React PerformanceđŸŸĸ Free Lesson

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.

MetricWhat it capturesGoodPoorMain lever in React
Largest Contentful PaintWhen the main content appears2.5 s or betterOver 4 sServer response, image priority, route splitting
Interaction to Next PaintDelay before the next frame after input200 ms or betterOver 500 msLong tasks, expensive effects, update storms
Cumulative Layout ShiftUnintended movement during load0.1 or betterOver 0.25Reserved space for media and async content
First Contentful PaintFirst pixel of rendered content1.8 s or betterOver 3 sRender-blocking CSS, blocking fonts
Time to First ByteLatency of the first response byte800 ms or betterOver 1.8 sEdge 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.

GateEnforced byThreshold to start fromConsequence of a breach
Initial JavaScript, gzippedSize limit in continuous integration170 kBBuild fails until a chunk moves out of the entry
Largest Contentful Paint, labLighthouse continuous integration2.5 s on a throttled runBuild fails and the diff is attached to the run
Interaction latency, fieldAlert on the p75 across releases200 msPage the owning team, block the next rollout
Layout shift, fieldAlert on the p75 across releases0.1Open a fix before the next feature release
Route level bundle growthBundle visualiser in the report10 percent per routeReview 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
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert React Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement