Description
The following code occurs in the `LogisticAggregator.add` method, which is a performance critical path.
val localCoefficients = bcCoefficients.value features.foreachActive { (index, value) => val stdValue = value / localFeaturesStd(index) var j = 0 while (j < numClasses) { margins(j) += localCoefficients(index * numClasses + j) * stdValue j += 1 } }
`llocalCoefficients(index * numClasses + j)` calls the `apply` method on `Vector`, which dispatches to `asBreeze(index * numClasses + j)` which creates a new Breeze vector, and then indexes it. This is very inefficient, creates a lot of unnecessary garbage, and we can avoid it by indexing the underlying array.