Skip to content

for better inferred effects, avoid relying on copyto!? #39

@nsajko

Description

@nsajko

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!.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions