Skip to content

In-place broadcast composed with other operations is allocating #44

@dcabecinhas

Description

@dcabecinhas

If f is just assignment a .= b then it doesn't allocate but if composed with + or * it does.

using ComponentArrays
using BenchmarkTools

a = rand(3)
b = rand(3)
c = ComponentArray(a = rand(3))
d = ComponentArray(a = rand(3))

function f(a,b)
           a .+= b
end

@btime f($a,$b);
#  15.156 ns (0 allocations: 0 bytes)

@btime f($c,$d);
#  42.662 ns (1 allocation: 112 bytes)

@btime f($a,$c);
#  15.188 ns (0 allocations: 0 bytes)

@btime f($c,$a);
#  42.043 ns (1 allocation: 112 bytes)

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