Hi there,
I am working on improving the memory allocation performance of my code and in learning about how to do so I came across the fact that tuples are much cheaper to store that vectors. For this reason I was trying to create all new temporary “arrays” that will not be modified in the function as tuples. These new arrays are created as combinations of Vector{Float64} arguments and therefore I have to convert the combination into a tuple within the function. Nevertheless I found this conversion to make the perfomance worst. Please refer to the following simple example:
Approach one:
vec1 = rand(3); vec2 = rand(3);
function test(vec1::Vector{Float64}, vec2::Vector{Float64})
temp1 = vec1 .+ 0.5
temp2 = vec2 .+ 0.8
return dot(temp1, temp2)
end
@benchmark test($vec1, $vec2)
The above gives this:
Approach 2:
vec1 = rand(3); vec2 = rand(3);
function test(vec1::Vector{Float64}, vec2::Vector{Float64})
temp1 = tuple(vec1 .+ 0.5...)
temp2 = tuple(vec2 .+ 0.8...)
return dot(temp1, temp2)
end
This second approach gives:
Can someone explain why this is so costly and whether there is any advice about how to avoid having to define new temporary arrays as Vectors to avoid the high memory estimate?
thanks a lot in advance!