StaticArrays.jl icon indicating copy to clipboard operation
StaticArrays.jl copied to clipboard

Allow mutation of non-isbits eltypes

Open MasonProtter opened this issue 2 years ago • 2 comments

For large MArrays, this'll be slower than if we had a proper MutableTuple, but it does work and should be pretty quick for reasonable sizes. It shouldn't screw up the garbage collector or do anything unsafe like the previous version did.

MasonProtter avatar Apr 03 '23 03:04 MasonProtter

That's so bizarre, this test works totally fine for me locally, and the operations it's doing should be legal.

MasonProtter avatar Apr 03 '23 16:04 MasonProtter

This works for me too, perhaps we can give it another try? What were the issues? (logs are no longer available)

I made an attempt as well, with some special-casing for certain mutable types (for which I believe the concerns of #27 do not apply): https://github.com/JuliaArrays/StaticArrays.jl/compare/master...serenity4:setindex-nonisbits. That seems to greatly improve performance for large arrays:

julia> mutable struct Mut; x::Float64; end

julia> @btime setindex!(v, $("ho"), 2) setup = v = @MArray ["ha" for i in 1:100];
  408.465 ns (3 allocations: 1.62 KiB)

julia> @btime setindex!(v, $(Mut(3.0)), 2) setup = v = @MArray [Mut(rand()) for i in 1:100];
  7.032 ns (0 allocations: 0 bytes)

Though this optimization could be implemented later and if we are really 100% sure it won't cause any issues. I'd just try to go forward with the current PR first.

serenity4 avatar Nov 18 '23 13:11 serenity4