Automatic memoization and manual memoization
React Compiler changes the default optimization strategy for modern React code.
Before Compiler, teams often asked: Where should I add memo, useMemo, or useCallback?
With Compiler, the better first question is: Is this component written according to the Rules of React so the compiler can optimize it safely?
Automatic memoization mental modelโ
function SearchResults({ query, items }) {
const visibleItems = filterItems(items, query);
return <Results items={visibleItems} />;
}
Compiler can analyze which reactive inputs affect derived work and preserve safe results across renders.
This reduces the need to write manual useMemo for many purely performance-driven cases.
React.memo before and after Compilerโ
Without Compiler:
const ProductCard = memo(function ProductCard({ product }) {
return <article>{product.name}</article>;
});
With Compiler, component-level reuse can often be generated automatically.
Compiler is not simply wrapping every component in memo.
useMemo still has semantic usesโ
Manual memoization remains useful when identity itself is part of an external or architectural contract.
const options = useMemo(
() => ({ locale, currency }),
[locale, currency]
);
Examples:
- an Effect depends on a deliberately stable object;
- an imperative third-party API stores an object identity;
- a migration relies on an existing identity contract;
- code must preserve behaviour across compiler-disabled and compiler-enabled paths.
useCallback can still express external identityโ
const handleChange = useCallback((value) => {
setValue(value);
}, []);
useEffect(() => {
externalWidget.subscribe(handleChange);
return () => externalWidget.unsubscribe(handleChange);
}, [handleChange]);
Here callback identity is not just a render-performance hint; an external system stores it.
Performance identity vs semantic identityโ
Do not delete existing memoization blindlyโ
Existing memo, useMemo, and useCallback may influence behavior, not just speed.
Removal can affect:
- Effect dependencies;
- third-party subscription identity;
- memoized children;
- intentional shared references;
- compiler output and optimisation coverage.
Treat deletion as a refactor, not cleanup by default.
Memoization does not fix architectureโ
A giant component with poor ownership does not become good architecture because its calculations are memoized.
Manual memoization can be harmfulโ
Overusing manual memoization adds:
- dependency arrays to maintain;
- stale-closure risk when dependencies are wrong;
- custom comparison bugs;
- extra complexity in reviews;
- memo bookkeeping that may cost more than the avoided work.
Use it for a reason you can explain.
memo custom comparisons require careโ
const Row = memo(RowImpl, arePropsEqual);
A custom comparison must account for all props that affect rendering and behavior. An incorrect comparator can preserve stale values or callbacks.
Do not write expensive deep comparisons to avoid a cheap render.
Compiler and derived objects/functionsโ
Inline objects and callbacks are not automatically performance bugs in a compiler-enabled codebase.
function Toolbar({ itemId }) {
const actions = {
onOpen() {
openItem(itemId);
},
};
return <ActionBar actions={actions} />;
}
Focus on correctness first. Measure before adding identity scaffolding manually.
Decision guideโ
Common mistakesโ
- wrapping every component in
memoeven with Compiler enabled; - replacing architecture work with memoization;
- deleting all
useMemo/useCallbackduring migration; - using deep custom comparators for cheap children;
- ignoring semantic identity required by external systems;
- treating a new object/function on every render as automatically wrong.
Production review checklistโ
- Is the performance problem measured?
- Is state located near the UI that owns it?
- Is DOM/list volume bounded?
- Is the compiler active for this code path?
- Is manual identity needed for an external/semantic contract?
- Does existing memoization have behavior implications?
- Do profiling results improve after the change?
Interview questionsโ
Junior: Does React Compiler make useMemo invalid?
Mid-level: When can manual useCallback still be appropriate in a Compiler-enabled application?
Senior: Explain the difference between performance identity and semantic identity, and how that distinction changes a Compiler migration plan.