$linuxjunkies
>

memoization

also: function result caching, function memoization

A programming optimization technique that caches the results of expensive function calls and returns the cached result when the same inputs occur again, avoiding redundant computation.

Memoization stores the output of a function so that if the function is called again with identical arguments, the previously computed result is returned instantly instead of recalculating it. This is particularly useful for recursive functions or operations with expensive calculations.

A classic example is computing Fibonacci numbers. Without memoization, fib(5) recalculates fib(3) multiple times. With memoization, fib(3) is computed once and its result is stored in a cache (usually a dictionary or hash table) for reuse.

In Linux development and scripting, memoization can optimize performance-critical sections—for example, caching DNS lookups, file metadata, or shell function results. Tools like ccache (C compiler cache) apply this concept to speed up compilation by caching object files.

Related terms