Course contentsShow
← React
Lesson 695 of 2,39618. When NOT to Use useEffectFree lesson

Expensive Computation Without Memoization

If computation is fast enough (< 5ms typical), just run it every render. Profile first—most computations don't need memoization.

What You'll Learn

You'll learn when to skip useMemo entirely and just compute values during render—because most computations are fast enough that memoization adds unnecessary complexity.

The Core Idea

Not every calculation needs useMemo. If a computation takes less than ~5 milliseconds (which is most of them), just run it on every render. The overhead of memoization itself (storing values, checking dependencies) can actually be slower than just recalculating.

Profile first, optimize later.

Why This Matters

We've learned that derived state should be computed during render, not in useEffect. But that doesn't mean every computation needs wrapping in useMemo. Most JavaScript operations are blazingly fast:

  • Filtering an array of 100 items? Fast.
  • Mapping over a dozen objects? Fast.
  • Calculating totals from a small list? Fast.

Only when you measure slowness should you reach for memoization.

The Default Approach

function ProductList({ products, searchTerm }) {
  // Just compute it! This is probably fast enough
  const filtered = products.filter(p => 
    p.name.toLowerCase().includes(searchTerm.toLowerCase())
  );

  return <ul>{filtered.map(p => <li key={p.id}>{p.name}</li>)}</ul>;
}

No useMemo needed unless profiling shows this computation causes lag.

When to Actually Optimize

  • You notice visible lag when typing or interacting
  • You profile with React DevTools and see slow renders
  • You're processing thousands of items, not dozens

React is fast. Your computer is fast. Trust that until proven otherwise.

Key Takeaway: Most computations don't need useMemo—compute directly during render and only optimize when profiling reveals actual performance problems.