Allocations when assigning Static Array in mutable struct

Probably these are benchmarking artifacts because you are not interpolating the variables:

julia> mutable struct Foo
           m ::SMatrix{3,2,Float64,6}
           v ::SVector{3,Float64}
       end

julia> foo = Foo(rand(SMatrix{3,2,Float64,6}),rand(SVector{3,Float64}))
Foo([0.8724518857438199 0.3632403606484935; 0.8892847298840123 0.12143759712364588; 0.7082712449691183 0.7665415510363147], [0.1758060685606172, 0.7266211355083249, 0.33830992545256433])

julia> @btime foo.v = x  # wrong
  47.284 ns (2 allocations: 64 bytes)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.982401257786785
 0.9164914648537852
 0.5761051073188066

julia> @btime $(foo.v) = $x  # correct
  1.640 ns (0 allocations: 0 bytes)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.982401257786785
 0.9164914648537852
 0.5761051073188066

julia> f() = @SVector [1., 2., 3.];

julia> @btime $(foo.v) = f()
  0.022 ns (0 allocations: 0 bytes)
3-element SVector{3, Float64} with indices SOneTo(3):
 1.0
 2.0
 3.0


3 Likes