Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing a SubArray without @inbounds prevents its allocation from being elided #29860

Closed
KristofferC opened this issue Oct 31, 2018 · 0 comments
Labels
arrays [a, r, r, a, y, s] performance Must go faster

Comments

@KristofferC
Copy link
Member

KristofferC commented Oct 31, 2018

For example:

julia> f(x) = view(x, :)[3]
f (generic function with 1 method)

julia> f2(x) = @inbounds view(x, :)[3]
f2 (generic function with 1 method)

julia> x = rand(3);

julia> @btime f($x);
  8.618 ns (1 allocation: 48 bytes)

julia> @btime f2($x);
  1.503 ns (0 allocations: 0 bytes)

Presumably, this is because it appears in a call to Base.throw_boundserror. Not surprising, but it means that many SubArrays hang around even though their only non-inlined usage is in an error branch.

@KristofferC KristofferC added performance Must go faster arrays [a, r, r, a, y, s] labels Oct 31, 2018
@KristofferC KristofferC changed the title Indexing any SubArray without @inbounds prevents its allocation from being elided Indexing a SubArray without @inbounds prevents its allocation from being elided Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

No branches or pull requests

1 participant