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

Delete unused arguments in subarray code #30789

Merged
merged 2 commits into from
Jan 23, 2019
Merged

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Jan 21, 2019

On my machine, this drops the time needed for the subarray tests from 300s to 185s. However, do not merge unless there isn't a performance impact. Also, @maleadt, please check to see if this breaks stuff for you (this is basically the opposite direction of #30666).

@nanosoldier runbenchmarks(ALL, vs = ":master")

@timholy timholy requested a review from mbauman January 21, 2019 22:21
base/subarray.jl Outdated
_indices_sub(S::SubArray) = ()
_indices_sub(S::SubArray, ::Real, I...) = (@_inline_meta; _indices_sub(S, I...))
function _indices_sub(S::SubArray, i1::AbstractArray, I...)
_indices_sub(@nospecialize(S::SubArray)) = ()
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this argument can just be removed completely? I don't see it used anywhere.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument to reindex also seems to be unused?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's there in case anyone wants to extend this for another array type? CC @mbauman.

Copy link
Sponsor Member

@mbauman mbauman Jan 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just historical cruft in all these cases.

I think when I was writing these methods I started out thinking I'd need it and then never culled things back down.

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@maleadt
Copy link
Member

maleadt commented Jan 22, 2019

Yes, this will probably break GPU code. It would be nice to be able to disable @nospecialize when doing GPU codegen, ref. https://github.com/JuliaGPU/CUDAnative.jl/issues/320, then this wouldn't be an issue. Pointers appreciated.

@mbauman
Copy link
Sponsor Member

mbauman commented Jan 22, 2019

Let's just remove all these un-used arguments? They weren't intended to provide space for external specialization, but I'm not sure if anyone has actually done it.

base/subarray.jl Outdated
(@_propagate_inbounds_meta; (idxs[1][subidxs[1], subidxs[2]], reindex(V, tail(idxs), tail(tail(subidxs)))...))

# In general, we index N-dimensional parent arrays with N indices
@generated function reindex(V, idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N}
@generated function reindex(@nospecialize(V), idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N}
Copy link
Sponsor Member

@mbauman mbauman Jan 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in this case we do use V to throw an error message — but it's an error message that should never occur because it should get caught at construction time. Edit: so I think it'd be just fine to throw a slightly less helpful error. Heck, the message even implores for a bug report which I've never seen.

@@ -164,6 +164,10 @@ function promote_eltype_op end

# @deprecate one(i::CartesianIndex) oneunit(i)
# @deprecate one(::Type{I}) where I<:CartesianIndex oneunit(I)

@deprecate reindex(V, idxs, subidxs) reindex(idxs, subidxs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be commented out like the lines above it, since we can't introduce new deprecations until 2.0, if I'm not mistaken.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are internal functions, so they don't need deprecations at all unless we're aware that people are using them and we want to be nice.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of any users, but this seemed harmless and better than throwing a MethodError.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW _indices_sub is not deprecatable, so this doesn't try.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly reminder to use a trailing false in cases like this to prevent unexported things from being exported. :)

#31201

@timholy
Copy link
Sponsor Member Author

timholy commented Jan 22, 2019

@nanosoldier runbenchmarks(ALL, vs = ":master")

@timholy timholy changed the title Add nospecialize to unused arguments in subarray code Delete unused arguments in subarray code Jan 22, 2019
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@timholy
Copy link
Sponsor Member Author

timholy commented Jan 23, 2019

I can't replicate the performance regressions locally (and the worst of them don't use any of the code I changed). The test failures look unrelated.

@maleadt, this version shouldn't impact GPU code.

@JeffBezanson JeffBezanson merged commit 81ef652 into master Jan 23, 2019
@JeffBezanson JeffBezanson deleted the teh/faster_subarray_tests branch January 23, 2019 15:02
mbauman added a commit that referenced this pull request Feb 28, 2019
It was inadvertently exported by #30789.  It's tailored to `SubArray` and doesn't check for preconditions that are enforced by the `SubArray` constructor — so while we could export it, I'd like to do so intentionally and add friendlier errors for violations of these preconditions.
fredrikekre pushed a commit that referenced this pull request Mar 1, 2019
* Don't export `reindex`

It was inadvertently exported by #30789.  It's tailored to `SubArray` and doesn't check for preconditions that are enforced by the `SubArray` constructor — so while we could export it, I'd like to do so intentionally and add friendlier errors for violations of these preconditions.

* Same deal for `substrides`
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.

None yet

6 participants