You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bounds-checking is currently considerably more expensive with an IdOffsetRange than with a Base.OneTo. For example, depending on how we define setindex!:
julia> x =zeros(Int, 10_000);
julia> y =OffsetVector(x, 0);
julia>fill1d(x) =for i inaxes(x,1); x[i] = i; end
julia>@btimefill1d($x);
10.634 μs (0 allocations:0 bytes)
# Current definition@inlinefunction Base.setindex!(A::OffsetVector, val, i::Int)
@boundscheckcheckbounds(A, i)
@inboundsparent(A)[parentindex(Base.axes1(A), i)] = val
A
end
julia>@btimefill1d($y);
16.032 μs (0 allocations:0 bytes)
# Alternate definition where bounds checking is forwarded to the parent@propagate_inboundsfunction Base.setindex!(A::OffsetVector, val, i::Int)
parent(A)[parentindex(Base.axes1(A), i)] = val
A
end
julia>@btimefill1d($y);
12.505 μs (0 allocations:0 bytes)
The present definition was only introduced to perform bounds-checking at the top level so that error messages reflect the indices of the OffsetArray and not that of the parent. However this appears to come with a significant performance penalty.
The trend also persists with larger arrays.
julia> x =zeros(Int, 10_000_000);
julia> y =OffsetVector(x, 0);
julia>@btimefill1d($x);
11.920 ms (0 allocations:0 bytes)
julia>@btimefill1d($y); # present definition17.342 ms (0 allocations:0 bytes)
julia>@btimefill1d($y); # forward bounds checking to the parent 13.341 ms (0 allocations:0 bytes)
Also: why is bounds-checking so expensive? Is it being performed per element? Should it not be possible to perform a bounds-check for the axis in one-go, and not per element?
The text was updated successfully, but these errors were encountered:
Bounds-checking is currently considerably more expensive with an
IdOffsetRange
than with aBase.OneTo
. For example, depending on how we definesetindex!
:The present definition was only introduced to perform bounds-checking at the top level so that error messages reflect the indices of the
OffsetArray
and not that of the parent. However this appears to come with a significant performance penalty.The trend also persists with larger arrays.
Also: why is bounds-checking so expensive? Is it being performed per element? Should it not be possible to perform a bounds-check for the axis in one-go, and not per element?
The text was updated successfully, but these errors were encountered: