Skip to content

Conversation

@jishnub
Copy link
Member

@jishnub jishnub commented Dec 22, 2020

This is a common case, so it might be worth the specialized method. Seems to cut down on allocations in certain applications, although the performance gain appears to be minimal.

On master:

julia> a = zeros(0:1000, 0:1000);

julia> function f(a)
       x = OffsetArrays.no_offset_view(a)
       sum(x[i] for i = 1:lastindex(x))
       end
f (generic function with 1 method)

julia> @btime f($a);
  1.701 ms (4 allocations: 96 bytes)

After this PR:

julia> @btime f($a);
  1.684 ms (0 allocations: 0 bytes)

Also uses Origin in the constructor to make it simpler.

@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #175 (04a67a0) into master (233a7b9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #175   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files           4        4           
  Lines         261      262    +1     
=======================================
+ Hits          259      260    +1     
  Misses          2        2           
Impacted Files Coverage Δ
src/OffsetArrays.jl 99.45% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 233a7b9...04a67a0. Read the comment docs.

@timholy timholy merged commit cd9b075 into JuliaArrays:master Dec 24, 2020
@timholy
Copy link
Member

timholy commented Dec 24, 2020

Thanks!

@jishnub jishnub deleted the no_offset_view branch December 24, 2020 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants