Skip to content

slow fallback array copyto! in Julia 1.7.0 #43287

@johnnychen94

Description

@johnnychen94

It looks like a potential type inference issue

using BenchmarkTools
X = rand(ComplexF32, 64, 64);

dst = reinterpret(reshape, Float32, X);
src = copy(dst);

@btime copyto!($dst, $src);
# 1.6.4: 42.120 μs (0 allocations: 0 bytes)
# 1.7.0: 800.737 μs (32768 allocations: 1.12 MiB)
# 1.8.0-DEV.1090: 829.629 μs (32768 allocations: 1.12 MiB)

Profiling the code shows that it's hitting the fallback dual-iterator implementation version and a slow Tuple iterator

julia/base/abstractarray.jl

Lines 1041 to 1047 in d16f480

# Dual-iterator implementation
ret = iterate(iterdest)
@inbounds for a in src
idx, state = ret
dest[idx] = a
ret = iterate(iterdest, state)
end

indexed_iterate(t::Tuple, i::Int, state=1) = (@inline; (getfield(t, i), i+1))

image

Downstream JuliaImages issues: JuliaImages/Images.jl#992 JuliaImages/ImageCore.jl#174 (cc: @etibarg @timholy)

Metadata

Metadata

Assignees

Labels

performanceMust go fasterregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions