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โ
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.
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.
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โ
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]);
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โ
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);
});
A Transition does not reduce total CPU cost. It changes priority and interruption behavior.
useDeferredValueโ
const deferredQuery = useDeferredValue(query);
query immediatelydeferredQuery and may lag behindThis 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.
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.
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.
Architecture checklistโ
When an update is expensive, ask:
- Who owns the state?
- Who actually needs it?
- Is any state duplicated or derived?
- Is Context too broad?
- Would a narrower external-store subscription help?
- Is this work urgent?
- Is the collection too large to render fully?
- Is the calculation expensive, or is the DOM/layout expensive?
- Could work happen on the server?
- 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.