Mutating a StructArray without allocation

Hi!

I haven’t used the package before, but it sounds like you are running into this issue?
https://juliaarrays.github.io/StructArrays.jl/stable/counterintuitive/

Considering this statement from the page,

A StructArray with immutable elements will in many cases behave identically to (but be more efficient than) a StructArray with mutable elements.

it does sound like using the immutable structs would avoid the issues. You could for example rewrite the method(s) operating on the structs to return a new instance:

function step(coord::Coordinate)
    return Coordinate(coord.x + rand(-1:1), coord.y + rand(-1:1))
end

function step_array!(s)
    for i in eachindex(s)
        s[i] = step(s[i])
    end
    return s
end

(Actually, the step! function in this example also doesn’t allocate with the mutable version of the struct either.)

Just an aside: Have you checked if you actually have a benefit of StructArrays.jl compared to a normal Array of your structs? I’m not sure if you will see much performance benefit when operating on single elements – it sounds like you want to rewrite your operations to operate on every field of each struct at once, since the fields are just stored as vectors internally.