I have a program that requires me to use my own array type. However, my own array definition seems to cause a type instability problem, leaving lots of performance on the table (potentially 2~3x improvements).
The issue can be reduced to the minimal working example below:
My program defines two custom array types
DenseArray. The former is essentially a wrapper on a Julia vector and the latter wraps on top of the
DenseArrayAccessor. In my actual program,
DenseArray contains other fields and supports other operations but those are unnecessary details for this question.
train function is what I am trying to optimize.
@code_warntype shows many warnings when
DenseArrays but those warnings are gone when I use
DenseArrayAccessor. Could someone please help me understand what caused this instability?