DEV Community

Cover image for Optimize the hell out of your  Javascript programs with Memoization.

Optimize the hell out of your Javascript programs with Memoization.

Ola' John Ajiboye on July 23, 2019

Many moons ago when I started learning algorithms, I had just learned recursion and was feeling like a Jedi. You know what they say?: "if all you h...
Collapse
 
mvoloskov profile image
Miloslav πŸ³οΈβ€πŸŒˆ πŸ¦‹ Voloskov

The point about people not using it is not quite right.

But people don't quite use it in JavaScript indeed. JavaScript is a frontend language after all, at least it was initially meant for it. Right before React, frontend was driven by "dirty", functionally impure things like jQuery.

Memoization is only possible in pure environments. Thus, it was receiving almost no traction whatsoever.

Aside of JavaScript, look at the functional landscape – people thrive on memoization in lisps, as well as on lazy evaluation, pattern-matching and other good old functional things.

Good things to come – modern frontend is moving towards functional concepts.

Memoization and other good things are to be resurfaced.

@akashkava

Collapse
 
mongopark profile image
Ola' John Ajiboye

Thanks a bunch for your input. You nailed the point. Because Javascript is easier to get started with it, it's easier to keep doing the dirty stuffs. But even at the moment React implements meomoization with React.Memo and stuffs.

Collapse
 
akashkava profile image
Akash Kava

I believe the word is called caching and its very old technique, but yes, people don't use it !!

Collapse
 
elmuerte profile image
Michiel Hendriks

Caching and memoization are related, but not the same. Caching is mutable, and generally constraint in size or time.

Catch invalidation is a thing, memoization invalidation is not.

In most cases you want caching. Only in certain algebraic cases you want memoization.

Collapse
 
mongopark profile image
Ola' John Ajiboye • Edited

Yea, you are correct. It's similar to caching but not exactly the same.

Collapse
 
luispa profile image
LuisPa

Great post!

Collapse
 
selahattinunlu profile image
Selahattin Ünlü

Wow, there is so huge difference between them.
I've never heard the memoization term before. Thanks, it was great!

Collapse
 
jamesthomson profile image
James Thomson

Great write up and use case for memoization. Amazing to see what a difference it can make when used in a use case like this. 🀯

Collapse
 
monicat profile image
Monica Macomber

Urgh!!, enough of the computer science jargons!. I don't even have a CS degree why should you trust my definitions.

I love all the personality in your article πŸ˜‚ Very helpful too, thanks.