Strange performance results about function mul! with views

Views with a Vector{Int} of indices are likely to hit slower paths than views with UnitRange, because their contents is less predictable:

julia> x = rand(5, 3);

julia> view(x, [1,3,2], :) isa StridedArray
false

julia> y = view(x, 1:3, :); y isa StridedArray
true

julia> strides(x) == strides(y) == (1, 5)
true

If 1:1 is what you really want, then there are probably further improvements available by using vector types, instead of 1xN matrices:

julia> @btime mul!(@view($aaaa[[1],:]), $bbbb, $cccc);  # slow path above
  24.499 ms (2 allocations: 64 bytes)

julia> @btime mul!(@view($aaaa[1:1,:]), $bbbb, $cccc);  # faster path above
  1.480 ms (0 allocations: 0 bytes)

julia> @btime mul!(@view($aaaa[1,:]), $cccc', $(vec(bbbb)));  # vector not matrix
  589.125 μs (0 allocations: 0 bytes)

3 Likes