Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.6.1, 4.X
-
None
-
None
-
master branch
3.6.1
-
Easy
Description
Inspecting BOBYQA performance, I see a lot of the time is spent into the getEntry method of Array2DRowRealMatrix.
At each getEntry, a costly MatrixUtils.checkMatrixIndex is performed.
See flamegraph.
It seems other implementations of `RealMatrix` also start by the `checkMatrixIndex`.
I did not check for complex matrices.
It is very likely using a try and catch IndexOutOfBoundsException will be way faster in the nominal case than checking indexes before accessing the array.
All consumers of `RealMatrix#getEntry` could benefit from this optimization.
See benchmark for a simple BOBYQA workload.
For this workload the performance gain is ~10%.
Before: bobyqa_matrix_getEntry_current.txt --> 120 ± 5 ms/operations
After: bobyqa_matrix_getEntry_withOpti.txt --> 106 ± 8 ms/operations
Other options:
1. replace matrix.getEntry(row, column) by matrix.getDataRef()[row][column] inside the Bobyqa implementation. According to my (very limited) benchmark results this is the fastest. But this would be specific to Bobyqa, and this makes the code harder to read, so this can be taken as a different task I guess.
2. add something like a fastGetEntry to the RealMatrix interface. This method would not perform the indexes checks. But I guess changing the interface is overkill.
Attachments
Attachments
Issue Links
- links to