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)