Skip to main content

Render Cost, State Placement, and Scheduling

React performance is often determined more by where state lives and how updates propagate than by manual memoization.

A useful question is:

What is the smallest part of the tree that actually needs to update?

Update scope starts with ownershipโ€‹

State ownership defines where an update begins
Hover state in App
App update โ†’ large subtree is reconsidered
Hover state in ProductCard
Only the local card owns and renders the hover update

Moving state closer to its true owner can outperform wrapping the whole tree in memo.

Lowest common owner, not lowest possible componentโ€‹

If two siblings coordinate selected state:

Page
โ”œโ”€โ”€ List
โ””โ”€โ”€ Details

Page may be the correct owner.

Where should this state live?
Only one component needs itKeep it local
Several siblings coordinate on itLift to their lowest common owner
Many distant consumers need a stable shared domainContext/store may be appropriate
It is remote cached dataUse server-state/framework data architecture

Do not push state downward so aggressively that coordination becomes duplicated or indirect.

Separate state by update frequencyโ€‹

A single Context containing currentUser, theme, mousePosition, notifications, and locale mixes slow and extremely fast domains.

Different update frequencies deserve different boundaries
Slow-changing
Auth ยท locale ยท theme
Moderate
Notifications ยท feature state
High-frequency
Pointer/streaming/live data

A high-frequency value should not automatically force every unrelated consumer of a giant Context value to participate.

Context is not selective by defaultโ€‹

const value = {
user,
logout,
};

<AuthContext value={value}>...</AuthContext>

When the provided value changes, consumers that read that Context update.

React Compiler may stabilize ordinary values automatically, but it does not change the ownership model. Very high-frequency or selectively consumed state may fit an external store better.

External stores and narrow subscriptionsโ€‹

External-store update flow
Store changes
External source owns state
Subscribers
React asks getSnapshot()
Affected consumers render
Narrow update surface

Selectors/store architecture can make subscription granularity much narrower than one monolithic Context value.

Keep derived data derivedโ€‹

Avoid storing a calculated value merely to recompute it in an Effect:

const [filtered, setFiltered] = useState([]);

useEffect(() => {
setFiltered(filterItems(items, query));
}, [items, query]);
Effect-derived state creates an extra cycle
1Render with old derived state
2Commit
3Effect recalculates
4setState
5Second render

Prefer:

const filtered = filterItems(items, query);

If calculation cost is measured as significant and inputs often remain stable, then consider Compiler or targeted useMemo.

Frequency ร— cost determines urgencyโ€‹

Update frequency and render cost are separate axes
Low frequency ยท low cost
Usually fine
Low frequency ยท high cost
Profile the interaction
High frequency ยท low cost
Often fine, measure
High frequency ยท high cost
Likely architectural bottleneck

A tiny 60 Hz update can still be cheaper than a 20 ms render on every keypress.

Urgent vs non-urgent updatesโ€‹

setInputValue(nextValue);

startTransition(() => {
setQuery(nextValue);
});
Scheduling can protect urgent interaction
Urgent input
Character should appear immediately
Transition results
Non-urgent ยท interruptible
Committed results
Catch up to latest query

A Transition does not reduce total CPU cost. It changes priority and interruption behavior.

useDeferredValueโ€‹

const deferredQuery = useDeferredValue(query);
Input
Uses canonical query immediately
Results
Use deferredQuery and may lag behind

This often preserves a simpler state model than manually maintaining both query and slowQuery.

Suspense and already-visible UIโ€‹

Transitions and deferred values can keep useful previous content visible during non-urgent work.

Preserve orientation when new work is pending
Preferred when appropriate
Old content stays visible + pending feedback
More disruptive
Old content disappears โ†’ spinner โ†’ new content

Boundary placement is both a performance and UX decision.

Large lists need bounded renderingโ€‹

When thousands of rows dominate DOM/layout/render cost, architecture matters more than per-row memoization.

Virtualization bounds mounted work
10,000 records
Full dataset
~30 mounted rows
Visible region + buffer

Other strategies include pagination, server filtering/sorting, reducing item complexity, and stable item identity.

<Row key={item.id} item={item} />

Keys preserve identity; they are not a performance trick.

Composition can reduce update fan-outโ€‹

The architectural goal is not to prevent all renders. It is to make update boundaries match ownership.

A wrapper that owns small local state should not automatically make unrelated expensive content depend on that state.

Avoid unnecessary global stateโ€‹

Good local candidates include open/closed state, hover state, a local form draft, one panel's selected tab, and temporary interaction state.

Shared/global state should earn its scope.

Server state has a different lifecycleโ€‹

Remote data includes freshness, loading, retry, invalidation, deduplication, pagination, and optimistic updates.

Treating it as generic global client state often creates duplicate caches and broad updates.

Use a server-state/query framework or framework data architecture for the lifecycle it actually has.

URL stateโ€‹

Filters, pagination, tabs, and search terms often belong in the URL when they are shareable, bookmarkable, navigation-relevant, or expected to survive reload.

Duplicating URL state into generic React state can create extra synchronization work.

Refs for non-rendering valuesโ€‹

Refs are appropriate for timer IDs, DOM nodes, third-party instances, and high-frequency imperative values that should not trigger rendering.

Do not hide render-relevant state in refs merely to reduce renders. If the UI must reflect a value, it belongs in state/store data.

Automatic batchingโ€‹

React batches many updates automatically:

setFirstName('Ada');
setLastName('Lovelace');

Do not combine unrelated state purely out of fear that multiple setters always mean multiple renders. Model state by meaning and ownership.

Avoid Effect feedback loopsโ€‹

useEffect(() => {
setState(transform(state));
}, [state]);

This can create repeated or infinite updates.

Where should the next value be calculated?
Direct result of current props/stateDuring render
Result of explicit user intentEvent handler / reducer
Owned by an external sourceAt the source/store boundary
Synchronization with an external systemEffect when genuinely needed

Architecture checklistโ€‹

When an update is expensive, ask:

  1. Who owns the state?
  2. Who actually needs it?
  3. Is any state duplicated or derived?
  4. Is Context too broad?
  5. Would a narrower external-store subscription help?
  6. Is this work urgent?
  7. Is the collection too large to render fully?
  8. Is the calculation expensive, or is the DOM/layout expensive?
  9. Could work happen on the server?
  10. Can API/prop shape reduce unnecessary churn?

Interview questionsโ€‹

Why can moving state improve performance?โ€‹

Updates begin where state is owned. Narrower ownership can reduce the amount of tree participating in each update.

When might an external store outperform Context?โ€‹

For high-frequency or selectively consumed external state where subscribers need narrow snapshot-based updates.

Does startTransition reduce render cost?โ€‹

No. It changes scheduling priority and interruption behavior; the work may cost the same CPU time.

Why is derived state often a performance smell?โ€‹

When derived through Effects, it creates duplicate sources of truth and extra render/commit/update cycles.

Referencesโ€‹