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

StructsOfArrays on Julia 0.7 doesn't elide boundschecks

Open vchuravy opened this issue 8 years ago • 0 comments

Running the example from the readme on 0.7.0-DEV.2484

using BenchmarkTools
using StructsofArrays

regular = complex(randn(1000000), randn(1000000))
soa = convert(StructOfArrays, regular)

function f(x, a)
    s = zero(eltype(x))
    @simd for i in 1:length(x)
        @inbounds s += x[i] * a
    end
    s
end

@benchmark f(regular, 0.5+0.5im)
@benchmark f(soa, 0.5+0.5im)

Leads to the disappointing result of:

julia> @benchmark f(regular, 0.5+0.5im)
BenchmarkTools.Trial: 
  memory estimate:  64 bytes
  allocs estimate:  2
  --------------
  minimum time:     786.494 μs (0.00% GC)
  median time:      817.898 μs (0.00% GC)
  mean time:        864.446 μs (0.00% GC)
  maximum time:     4.601 ms (0.00% GC)
  --------------
  samples:          5757
  evals/sample:     1

julia> @benchmark f(soa, 0.5+0.5im)
BenchmarkTools.Trial: 
  memory estimate:  64 bytes
  allocs estimate:  2
  --------------
  minimum time:     1.091 ms (0.00% GC)
  median time:      1.261 ms (0.00% GC)
  mean time:        1.359 ms (0.00% GC)
  maximum time:     7.935 ms (0.00% GC)
  --------------
  samples:          3661
  evals/sample:     1

and inspection of the @code_llvm shows that there are still oob blocks visible and no vectorization is happening.

vchuravy avatar Nov 12 '17 21:11 vchuravy