Skip to content

Performance regression in unsafe_getindex #14594

@KristofferC

Description

@KristofferC

I looked at https://github.com/jrevels/BaseBenchmarkReports/blob/master/c70ab26/c70ab26_vs_adffe19.md which is a test benchmark run that @jrevels ran that compares 0.4.2 with master. There are multiple regressions and I believe that most of them are from changes to unsafe_getindex, and more specifically, _checksize

For example, the benchmark:

function sumvector(A, n)
    s = zero(eltype(A)) + zero(eltype(A))
    nrows = size(A, 1)
    ncols = size(A, 2)
    r = rand(1:nrows, 5)
    for k = 1:n
        for i = 1:ncols
            val = Base.unsafe_getindex(A, r, i)
            s += first(val)
        end
    end
    s
end

Benchmark with A = rand(300, 500).

Master:

julia> @time sumvector(A, 1000);
  0.126164 seconds (2.00 M allocations: 83.924 MB, 6.93% gc time)

0.4.2:

julia> @time sumvector(A, 1000)
  0.034920 seconds (1.00 M allocations: 61.035 MB, 7.24% gc time)

Profiling shows that the extra time is spend in _checksize at

_checksize(A::AbstractArray, dim, I, J...) = (size(A, dim) == length(I) || throw_checksize_error(A, dim, I); _checksize(A, dim+1, J...))

CC: @mbauman since it was last touched in the scalar dimension drop change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions