FrontendIntermediate
Memoization
Pronunciationmem-oh-uy-ZAY-shun
Definition
An optimization technique that caches the return value of a function based on its inputs, so it doesn't need to recalculate when the same inputs occur again.
Where you hear it
In code reviews, performance tuning discussions, and when optimizing React components.
Examples
We used memoization to prevent the heavy calculation function from running on every render.
Applying memoization to the filtered list component significantly improved the UI responsiveness.
The price function caches its result for each product id, so repeated calls are instant.
Common mistake
Applying memoization to every single function by default, which adds unnecessary memory overhead and complexity without any performance gain.
Don't confuse with
Memoization caches the result of a function call based on inputs, while caching usually refers to storing broader data like API responses or database queries for later use.
Say it at work
- In a meeting or chat
Let's add memoization to this expensive calculation so it doesn't re-run on every state change.
- In an email or ticket
We should consider applying memoization here to resolve the noticeable UI lag during filtering.