In case itβs worth, I also experienced significant slowdown in Julia 1.6 on loops where no tuples were involved:
using StatsBase:sample
using BenchmarkTools
n_obs = Int(1e6)
n_vars = 100
n_bins = 64
K = 3
π = collect(1:n_obs)
Ξ΄ = rand(n_obs, K)
hist = zeros(K, n_bins, n_vars);
X_bin = sample(UInt8.(1:n_bins), n_obs * n_vars);
X_bin = reshape(X_bin, n_obs, n_vars);
function iter_1(X_bin, hist, Ξ΄, π)
hist .= 0.0
@inbounds for i in π
@inbounds for k in 1:3
hist[k, X_bin[i,1], 1] += Ξ΄[i,k]
end
end
end
π_sample = sample(π, Int(n_obs / 2), ordered=true)
`
Julia 1.5.3:
julia> @btime iter_1($X_bin, $hist, $Ξ΄, $π_sample)
1.224 ms (0 allocations: 0 bytes)
Julia 1.6.0:
julia> @btime iter_1($X_bin, $hist, $Ξ΄, $π_sample)
1.648 ms (0 allocations: 0 bytes)
Adding @simd
into the loop had little or no effect on performance (from 1.22ms to 1.19ms on 1.5.3 and 1.64ms to 1.62ms on 1.6.0)