Fix type stability issue with SubDiskArray #139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into a performance issue that I traced to a type instability in
size(a::SubDiskArray)
.In the existing definition of SubDiskArray
the child view is only parameterized by two of the five type parameters of
SubArray
, so it is a field with an abstract type, which leads to the type instability.There are a few ways to fix this. The way proposed in this pull request is to parameterize by all of the type parameters of
SubArray
:which gives the child array a concrete type and fixes the type inference problem and my performance issue. One could also do something like
or try to put some constraints on
P
,I
, andL
from the types of the parent array. I don't think I understand the whole DiskArrays codebase enough to work out the correct form of that last option, though.I've also added a test that throws an error with the current type instability and does not error with the new type definition.