Memoization

Memoization is a design pattern in which the result of a function’s execution is cached, and the cached result is returned when the function is subsequently called with identical inputs, thus avoiding redundant computation.

Memoization is a form of caching, but it is specifically used to optimize the performance of functions that are computationally expensive or time-consuming. It is the basis of the dynamic programming approach to algorithm design, where overlapping subproblems are solved once and their results reused.

Memoization is related to lazy loading, which likewise defers work until it is needed — though lazy loading defers the loading of a resource, while memoization caches the result of a computation.