Title: improving performance in access to multidimensional array elements

This is a performance issue concerning any matrix-esque object backed by a multidimensional array. I know it relates to GMatrix, but could include others. (GMatrix is the only one I've decompiled to look at.)

While pawing through GMatrix, I noticed that systematic element access is performed in an element-by-element manner. However, when accessing the elements of a multi dimensional array, making use of the row major implementation to grab the row array first, and then accessing elements in the row may improve performance. This way, you only index into single dimension arrays, which is faster.

The attached file demonstrates the improved performance in a matrix copy operation. Here is a sample of the results. Improvement varies with matrix geometry. Parameters are #rows, #columns, #copies. Values printed are millisecs.

C:\ >java MatrixCopyTest 4 4 3000000

ebe 5484

row 1266

improvement 76.91466083150985 %

ebe takes 333.17535545023696 % longer

C:\ >java MatrixCopyTest 100 20 500000

ebe 29250

row 14718

improvement 49.68205128205128 %

ebe takes 98.7362413371382 % longer

C:\ >java MatrixCopyTest 20 100 500000

ebe 18844

row 14391

improvement 23.630863935470177 %

ebe takes 30.942950455145578 % longer

I hope this isn't a well known/well trod issue. I searched the message history and saw no discussion of it.

Alan

<<MatrixCopyTest.java>>

Attachment: MatrixCopyTest.java
Description: Binary data

Reply via email to