I was really interested in this question Linked Arrays. According to that question, linked arrays make performance better. The asker linked what intrigued them to the topic. It was a Dev Forum post about Basics of Optimization by a user known as BlueTalsem. One of his ways of optimizing was memoizing expensive functions. Link here. I assumed that expensive functions are functions that make performance worse or take too much memory. I got interested. I found this git-hub page.
##This is what I understood: Memoized functions gets the results of a function. It's parameter is the function it gets the results of that argument. It has an optional argument which is its cashe. This is the place where the memoized function is stored. If not, it will default to its own table.
Memoized functions improve performance for memory. To get that memory back, you just simply make the memoized function nil.
When I was reading, I noticed this
local sum = function(...)
local result = 0
local params = { ... }
for i = 1, #params do
result = result + params[i]
end
return result
end
local memoized_sum = memoize(sum)
print(memoized_sum()) -- 0
print(memoized_sum(1)) -- 1
print(memoized_sum(1, 2)) -- 3
print(memoized_sum(3, 1)) -- 4
memoized_sum = nil
I have added the memoized_sum = nil to retrieve the memory back
The git-hub page said that the internal cache structure would be like this:
{
results = { 0 },
children = {
[1] = {
results = { 1 },
children = {
[2] = {
results = { 3 },
}
}
}
[3] = {
children = {
[1] = {
results = { 4 },
}
}
}
}
}
However, the problem is that there is no such function called memoize(). So, what can I do to make memoized functions and if I have misunderstood memoized functions or I still need to know more, please tell me by using answers
Thank you!
.

2 comments
"memoize" is this if you looked at the variables on the top of spec/memoize_spec.lua. The module code is https://github.com/kikito/memoize.lua/blob/master/memoize.lua. (I don't have the time to make a proper answer.)
Okay, so, I should do a few edits and then I can use this as a module