Memoization

Memoization is a technique that improves the speed of a program by storing any new inputs for future reference, if needed. This cuts down on any repeated computations in the program where the same inputs are being used to return the same result.

This technique gets its name from the Latin word, “memorandum”, which means to be remembered. Memoization can be applied to many contexts in computer programming, including:

  • Making calls to recursive or pure functions where some calculations use the same inputs and return the same outputs.
  • Fetching from the server with the same base API endpoints.

Memoization can be implemented in most programming languages, including JavaScript and Python. However, while memoization saves performance time, it comes with a cost in memory space since it is caching results that were already calculated.

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn More on Codecademy