Hi,
I have been trying to improve the performance of my code. The function below had 7 allocations before and some warning when using @code_warntype
. I made several changes that reduced allocations from 7 to 1 and removed the red ink from @code_warntype
. Is it possible to make the allocations to zero in this function?
Using TimerOutputs.jl I could not find which line is allocating. Individually, it seems all lines have zero allocations.
Thank you for reading…
function construct_tuple(arr1, ::Val{n1}, ::Val{m1}, ::Val{m2}, arr2) where {n1, m1, m2}
len_arr1 = length(arr1)
tup1 = (len_arr1 > n1) ? ntuple(i -> (@inbounds arr1[end-n1+i]), n1) :
ntuple(i -> i <= len_arr1 ? (@inbounds arr1[i]) : :N, n1)
len_arr2 = length(arr2)
tup2 = (len_arr2 > m1) ? ntuple(i -> (@inbounds arr2[end-m1+i]), m1) :
ntuple(i -> i <= len_arr2 ? (@inbounds arr2[i]) : :N, m1)
tup3 = len_arr2 >= m2 ? ntuple(i -> (@inbounds arr2[i]), m2) :
ntuple(i -> i <= len_arr2 ? (@inbounds arr2[i]) : :N, m2)
(tup1, tup2, tup3)
end