This article was originally posted on malikbrowne.com.
Last week, I was browsing different articles for guidance on the new lifecycle methods in ...
For further actions, you may consider blocking this person and/or reporting abuse
It took me a while to understand memoization. I wish I'd had this guide!!
I did too. If this helps one person struggle less than I did to understand this this post was worth the time. :)
While I agree about preventing premature optimization, on recursive functions like your factorial function memoization can store intermediate results, leading to optimized performance even if you don't call the function with the same parameter.
For instance,
factorial(4999)
could be faster if factorial memoizes all intermediate values from 4999 to 0. Of course, it means a bigger memory cost since the cache will no longer contain 1 value but 5000. But I think the best use case for memoization is on recursive pure functions.The drawback is that you can't memoize a function from the outside like you did with memoize-one: the function must be implemented with its own cache.
A great example in React land is reselect. See their section on Motivation for Memoized Selectors.
Reselect is great, and is probably one of the most popular tools used along with Redux.
A cool thing to note is that reselect allows you to pass in custom equality checks, or your own memoization function. I've played with it in the past - it's pretty cool.
Thanks for the great post malik. Awesome points about memory leaks!
Very small correction: Lehman's terms should be layman's terms
ahhhh, thank you! i made the correction. :)
Thank you so much. I am new in functional world
Ah this is fantastic, great write-up! I've always meant to learn more about this.
Haha same here, figured I'd just write a blog post while I learned more about it too! :)
Awesome post! Thank you!
No problem, glad you liked it.