0% completed
In this section, you will learn about an important optimization technique that can play a crucial role in the performance of your React app called Memoization. At the end of the section, you'd be able to identify and use the best suited technique for your application. Without further ado, lets get straight into it.
Memoization is an optimization technique primarily used to enhance the performance of functions by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
The term "memoization" is derived from the word "memo", which refers to a note or a reminder. In programming, it acts as a reminder for the function to avoid redundant calculations. When a function is called, it typically processes input parameters to produce an output. If the function is computationally intensive or called frequently with the same parameters, it can lead to performance bottlenecks.
Memoization addresses this issue by maintaining a cache (often implemented as an object or a map) that stores the results of previous function calls. When the function is invoked, it first checks if the result for the given input is already in the cache. If it is, the cached result is returned immediately, bypassing the need for recalculation. If not, the function computes the result, stores it in the cache, and then returns it.
The primary benefit of memoization is its ability to significantly reduce the time complexity of functions that are called repeatedly with the same arguments. By caching results, memoization transforms a potentially exponential time complexity into a linear or constant time complexity, depending on the implementation.
This optimization technique can be used in the following scenarios:
In the next few lessons, you'll learn how to apply memoization using different components and hooks.
.....
.....
.....