JuliaCollections / Memoize.jl

@memoize macro for Julia
Other
177 stars 22 forks source link

Ability to turn off memoization for benchmarking #79

Open lstagner opened 1 year ago

lstagner commented 1 year ago

I've been benchmarking some code and it would be nice to be able to turn off memoization. Something like memoize!(false) which sets a global switch.

cstjean commented 1 year ago

If that can be done without a performance impact, then sure...

Note that you can already achieve the same thing on your side with:

use_memoize = true
struct OptionalMemoizer
    memo
end
haskey(om::OptionalMemoizer, key) = use_memoize ? haskey(om.memo, key) : false
...

and then use @memoize OptionalMemoizer(Dict() function ...

Another tack would be to run this interactively:

@eval Memoize macro memoize(fdef)
    esc(fdef)
end
Revise.revise(module_you_want_to_disable_memos)