tch-a-5yrOld__MEMOIZATION

Obodo David
2 min readMay 29, 2020

--

This article is a story that I believe should help you understand the concept. We wouldn’t write any code.

There lived a skilled carpenter named Evan Isaac, since time memorial there was nothing anyone asked him to make that he wasn’t capable of making.

One day Favour, a small calm beautiful 12 yr old girl got her first phone. Mr Isaac please would you show me a chair so i can take a picture of it? Mr Isaac took all his tools and within 5 minutes a chair was ready. He showed Favour the chair and she went back home so happy.

Two weeks later Favour came to Mr Isaac’s shop and asked the same question, please would you show me a chair? Mr Isaac being the smart carpenter he was remembered that he had made a chair previously, so he went to the room where he keeps all the things he had made, picked up the chair and showed Favour, all within 5 seconds.

Favour was surprised that it took much less time to see the chair this time around, until Mr Isaac turned and said, “I kept the chair you asked me to make 2 weeks ago”.

BIG TERMS defined with respect to the story

Input: Please show me a chair

Function: Mr Isaac making a chair

Output: Showing Favour a chair

Cache : store

Cached result : Former chair that was stored in room

Memoization: returning the chair in the store instead of making a new chair

The concept of memoization is same everywhere. I got inspired to write this article after learning memoizations application in React using React.memo().

React.Memo ensures that if a component is to be rendered with the same props(input) multiple times, a cached result of the component is sent(i.e the component is not re-rendered).

I believe with this short piece, you should now be able to dive deeply into the concept of memoization and fully understand it.

--

--