melpon/memoize

Is it discouraged to pass a map (containing multiple key values) as a parameter to a memoized function?

puruzio opened this issue · 2 comments

This is a question not an issue.

Let's say there is a memoized function like this. Will Memoize perform better/faster or use less memory if I pass current_user.id instead of a current_user map as the parameter? Or does it matter?

Option 1:

defmodule Search do
  use Memoize
  defmemo run(current_user)  do
       convert(current_time, current_user.timzone)
       search(current_user.id)
 end
end

Search.run(%{id: "1234", name: "John Doe", timezone: "America/Los_Angeles"})

Option 2

defmodule Search do
  use Memoize
  defmemo run(current_user_id)  do
       current_user = User.get!(current_user_id)
       convert(current_time, current_user.timzone)
       search(current_user.id)
 end
end


Search.run(1234)

Naturally, Option 2 would use less memory for Memoize, and probably has better performance as well.

Thank you!