Skip to main content
Web DevPerformance & OptimizationDiagramBeginner

Memoization

KO: 메모이제이션 (Memoization)·EN: Memoization·JA: メモ化(Memoization)

An optimization technique that caches the return value of expensive pure functions or component renders keyed by their inputs to skip redundant recomputation

Table of Contents

Structure Diagram

Cumulative Cost: Recompute vs Memoized Cache Hit
Computed OnceWasted Re-workRepeated Calls (Same Input) →Cumula
(50, 54)Recompute Every Time #3
Quick Answer

What is Memoization?

An optimization technique that caches the return value of expensive pure functions or component renders keyed by their inputs to skip redundant recomputation. It is a core concept in Performance & Optimization within Web Dev.

Core Principles

Memoization is a classic time-space tradeoff: it stores the output of an expensive pure function in memory keyed by its arguments, returning the cached result immediately on subsequent calls with the same inputs.

In modern frontend frameworks, memoization appears in React's useMemo, useCallback, and React.memo, as well as Vue's computed properties—preventing unnecessary recalculations and subtree reconciliations during re-renders.

Practical Takeaways

  • Measure before memoizing: Wrapping trivial calculations in useMemo adds dependency-comparison and memory overhead that can outweigh the savings. Focus on genuinely expensive derivations or preserving referential equality for memoized children and effect dependencies.
  • Watch unstable object/function references: Passing fresh inline literals (style={{ ... }}) or callbacks defeats shallow equality checks in React.memo.
  • Bound cache size for general functions: An unbounded memoization map over arbitrary inputs becomes a memory leak; cap it with an LRU eviction policy.

Notable Examples

  • Derived table filtering and aggregation: Caching filtered/sorted datasets with useMemo so unrelated UI state toggles don't re-run O(N log N) sorts.
  • State selectors (Reselect): Returning stable derived references from global stores to prevent cascading component re-renders.