More memory usage improvements
Andrew Smith | 1 October, 2008 | 19:31
Fiddled with memory some more. Basically all my fixes have been: getting local variables and memory allocations out of functions that are called in the update/render loop.
The savings are significant - the 100 spinning teapots used 6MB/sec last week and only 1.4MB/sec now. That’s more than 60% better. Of course that’s not a lot if one were expecting orders of magnitude.
This can actualy be taken down to almost nothing (in relative terms). And I’ll tell you how, but I won’t do it myself.
The function Matrix::multiplyMatrixByVector() is called in the update loop. It allocates a vector, and returns it. That replaces the primitive’s left/up/dir/pos via the rotateOnAxis() function, which in other words is a malloc/free loop with a lot of horrible memory consuming abstraction around it.
I tried fixing it in the same way I fixed the rest of the stuff - added a dest parameter to multiplyMatrixByVector(), and put the results in there. It didn’t work.
Why it didn’t work I can’t tell you, I can’t explain the bhaviour I’m seing. Symptoms range (depending on implementation) from a stream of warnings about zero-length vectors to ‘dest is undefined’ javascript errors in the console.
Whomever wants to give this a shot - what you need to do is replace this:
this.dir = multiplyMatrixByVector(rotateOnAxisMat, this.dir);
whith this:
multiplyMatrixByVector(rotateOnAxisMat, this.dir, this.dir);
in Primitive::rotateOnAxis(). Yes, I noticed it’s the same variable, and I know it’s passed by reference. I couldn’t find a reason that should be a problem.
