Skip to main content

Posts

Showing posts from September, 2023

Improve website performance - Javascript Memoization

Memoization What is Memoization? Memoization is a technique used in programming to write optimizied code. This is very useful in use cases when the system is performing very CPU intensive tasks repeatedly. What are the use Cases for Memoization? Memoization can be useful when the system is performing same task again and again like API output caching - This is not recommended though as it requires a cache invalidation mechanism which is tricky to implement. Calling a recursive function e.g. Fibonacci series. One thing to note here is, memoization works well in case of pure function only. What is a Pure function ? A function which produces the same output for the same given input every time. Lets understand this with the Fibonacci series example. Below program is written without memoization where result of previously executed function is not cached. So each time the program calls the Fibonacci function, it calculates results every time. Now, below is the improved memoized version o