The copyto! methods for Memory and Array in Base are currently implemented using a ccall to memmove. While this is fast, it results in worse effects than with a naive implementation:
julia> Base.@assume_effects :terminates_locally function copyto_naive!(dst::Union{Memory, Array}, src::Union{Memory, Array})
for i ∈ 0:(length(dst) - 0x1)
dst[begin + i] = src[begin + i]
end
dst
end
copyto_naive! (generic function with 1 method)
julia> Base.infer_effects(copyto!, NTuple{2, Vector{Float32}})
(!c,!e,!n,+t,+s,!m,!u,+o,!r)
julia> Base.infer_effects(copyto_naive!, NTuple{2, Vector{Float32}})
(!c,?e,!n,+t,+s,?m,+u,+o,+r)
A separate issue is that the generic copyto! may be doing aliasing checks, which is wasted effort for Collects.jl.
So it might make sense to implement a simplified replacement for copyto!.
The
copyto!methods forMemoryandArrayinBaseare currently implemented using accalltomemmove. While this is fast, it results in worse effects than with a naive implementation:A separate issue is that the generic
copyto!may be doing aliasing checks, which is wasted effort for Collects.jl.So it might make sense to implement a simplified replacement for
copyto!.