1

First of all, sorry for my bad English, but I need your help.

I have developed a simulation program with java swing where I have used lots of matrix calculations. My program is just finished but I need to speed up my performance. So I have used the java visual vm profiler to identify performance problems. I recognized that the initialization of Jama Matrices needs a lot of time. After running my program I had over 3 MB allocated Objects by JAMA. That's a lot of, isn't it? I think that's why the performance is bad.

Is there any better library than jama for matrices? I am using 3x3 matrices and I need multiplication and inverse operations or is there anything else i can do?

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
blueArrow
  • 11
  • 1

1 Answers1

1

Usually matrix math libraries are not optimized for speed on small matrices. You can see for yourself by taking a few stackshots, which are liable to show a large fraction of time in overhead functions like memory allocation and option checking.

What you can do instead (which I've done) is write special-purpose routines to do the multiplication and inverse, since you know the matrices are 3x3. Multiplication is trivial and you can unroll the whole thing.

Inverse of a 3x3 matrix can also be done in less code than coffee :) Wikipedia gives you the formula.

Whatever you do, try to minimize memory allocation.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135