Skip to main content

Measure Before Optimizing

Performance engineering starts with one question:

What is actually slow for the user?

React can feel slow because of JavaScript, React render work, Effects, network waterfalls, bundles, hydration, layout/paint, third-party scripts, server work, excessive updates, or poor scheduling. memo, useMemo, and useCallback address only part of that space.

Interaction performance is a pipeline​

One interaction crosses React and the browser
1User input
2Event handler / state update
3React render
4Commit + layout Effects
5Browser style / layout / paint
6Passive Effects

A slowdown can happen at any stage. A React-specific optimization cannot fix a late network request, a huge third-party script, or a browser layout bottleneck.

Define the symptom precisely​

β€œApp is slow” is not actionable.

β€œTyping in the search box takes 150 ms before the character appears when 10,000 rows are visible” gives you an interaction, dataset, and measurable outcome.

Reproduce before changing code​

A useful performance experiment is repeatable
1Same page/build
2Same dataset/cache state
3Same interaction
4Same measurements
5Compare before vs after

Without controlled conditions, optimization becomes guesswork.

Measure in the right environment​

Development React intentionally performs extra diagnostics. Strict Mode can repeat some work in development.

Development
Best for debugging correctness and causes
Profiling build
Instrumentation closer to production behavior
Production
Final user-facing validation

Do not treat development timing as production truth.

Browser Performance panel vs React profiling​

Use the tool that can see the suspected cost
Browser Performance
JS tasks Β· event timing Β· network Β· style Β· layout Β· paint
React DevTools / Profiler
Which components rendered Β· commit cost Β· update causes
React Performance Tracks
Blocking Β· Transition Β· Suspense Β· Effects alongside browser work

React 19.2 Performance Tracks can place React scheduling and component work directly on supported browser performance timelines.

Find the dominant cost​

Suppose a click trace shows:

Optimize the largest contributor, not the most familiar API
React render
40 ms
Browser layout
80 ms
Visible result
User waits for both

Reducing React render from 40 ms to 30 ms helps, but layout remains the dominant bottleneck.

Render count is not the performance metric​

50 renders Γ— 0.05 ms
2.5 ms total
1 render Γ— 120 ms
120 ms total

Rendering is normal. Investigate work that is expensive, frequent, or disruptive enough to affect the user.

Frequency and cost are separate dimensions​

Prioritize high-frequency, high-cost work
Low frequency + low cost
Usually fine
Low frequency + high cost
Profile the interaction
High frequency + low cost
Often acceptable, measure
High frequency + high cost
Likely bottleneck

For too-frequent updates, consider narrower subscriptions, refs for non-render values, fewer state updates, or architecture changes. For expensive individual renders, consider algorithms, virtualization, server work, component boundaries, or targeted memoization.

Find what triggered the update​

A component can render because its own state changed, an ancestor rendered, Context changed, an external-store snapshot changed, Suspense retried, a Transition progressed, or framework navigation updated the tree.

Do not assume props are the cause.

Cascading updates​

Derived state in Effects can create avoidable extra work
Render A
UI computed
Effect
Derives value and calls setState
Render B
Second render that may have been avoidable

If the value could have been derived during render, the Effect created unnecessary work.

Network waterfalls​

Serial data dependencies can dominate the page
Waterfall
fetch user β†’ render child β†’ fetch projects β†’ fetch permissions
Parallel start
start user + projects + permissions together when independent

Server Components, framework data APIs, preloading, and Suspense-aware data systems can help coordinate this. useMemo cannot fix a waterfall.

Bundle and hydration cost​

Measure initial JavaScript, route chunks, duplicated dependencies, editor/chart libraries, third-party scripts, and broad 'use client' boundaries.

Server-rendered HTML arriving early does not mean hydration is cheap. Hydration still loads client code, evaluates components, attaches behavior, and can run expensive calculations.

Scheduling and reducing work are different​

Different performance tools solve different classes of problems
Memoization
Avoid/reuse some repeated work
Transition/deferred
Change priority and interruption behavior
Algorithm/virtualization/server/worker
Reduce, move, or bound the work itself

A Transition can keep urgent input responsive, but it does not make a 200 ms calculation cost 20 ms.

Practical optimization workflow​

Evidence-driven performance loop
1Define user-visible problem
2Record baseline
3Locate dominant cost
4Change the largest cause
5Measure again
6Remove unjustified complexity

Example baseline:

filterRows(): 70 ms
Row tree render: 55 ms
browser layout: 15 ms

Possible fixes should target the dominant cause: data indexing, server filtering, virtualization, deferred rendering, or memoizing a verified expensive transformation.

Performance budgets​

Budgets should describe user-facing outcomes: search input responsiveness, route-to-useful-content timing, modal opening without input freeze, or smooth list scrolling under realistic data.

The exact target depends on the product, device, and network population.

Common mistakes​

  • Adding memoization everywhere before measuring.
  • Benchmarking only development mode.
  • Optimizing raw render count instead of user-visible latency.
  • Ignoring browser layout/paint.
  • Ignoring network or server architecture.
  • Comparing different scenarios before and after.

Production rule of thumb​

Optimization order
1 Β· Correctness
The UI must be right first
2 Β· Architecture + measurement
Own state/data/work correctly and find the bottleneck
3 Β· Targeted optimization
Change the measured cause
4 Β· User impact improved
Keep the change only if it helps

Interview questions​

Why start with profiling?​

Because slow UX can come from React rendering, JavaScript, network, browser layout/paint, hydration, Effects, server work, or third-party code. Profiling locates the dominant cause.

Is reducing render count always an optimization?​

No. Cheap renders can be harmless, while one expensive render can block the user. Measure time and impact.

Reducing work vs scheduling work?​

Reducing work lowers total computation. Scheduling APIs change when work runs and whether it is interruptible.

Common React source of cascading updates?​

Using Effects to derive state that could have been calculated during render, creating render β†’ commit β†’ Effect β†’ update β†’ second render.

References​