Closed Moelf closed 2 years ago
I am happy to change this, but just a question: is the allocation always there with this paradigm, or only if you combine it with interpolation?
expanding: https://github.com/JuliaLang/julia/pull/41826#issuecomment-894843480
julia> using LRUCache
julia> function func_lru(ctr, a)
_getter() = a + 1
get!(_getter, cache_lru, (ctr, a))
end
julia> const cache_lru = LRU{Tuple{Vector{Int},Int},Int}(maxsize = 10)
LRU{Tuple{Vector{Int64}, Int64}, Int64}(; maxsize = 10)
julia> function main()
ctr = Int[0]
for i = 1:10
println("Run $i")
println("Using Dict: $(@allocated func_dict(ctr, 1))")
println("Using IdDict: $(@allocated func_iddict(ctr, 1))")
println("Using LRU: $(@allocated func_lru(ctr, 1))")
end
end
Run 4
Using Dict: 0
Using IdDict: 32
Using LRU: 80
...
https://github.com/JuliaCollections/LRUCache.jl/blob/c55095c4a48ace9b49040570dd02c64942d11947/src/cyclicorderedset.jl#L111 probably needs the same treatment as: https://github.com/JuliaLang/julia/pull/41826
see discussion there.