1
Vote

Solution to giant speed improvement

description

Ohhh MY GOD!!
Replace everywhere, where possible all method calls with structs, with "ref struct", instead of struct.
Where are you guiys from, from the Java world? From Delphi? No other way to explain this. It goes through the whole code. You make massive calls to methods where you give over 5, in words: five structs! Without "ref"! These structs will be copied and cloned in every call you make, every time! They behave like "C++" structs! But I am almost shure, in the original "C++" Bullet Code were the methods declared this way: "Matrix &m" (& == ref). Do this everywhere in your code where it was done in the C++ original, and you should see a giant speed improvement!
Of course it makes no sense to use "ref" when you need a copy of the struct for the called method anyway. So you have to look at each method call with structs (Vector2, Vector3, Matrix...) and consider if you commit it by "ref" or by copy.
 
(The project I looked at was "Bullet XNA")
 
I wrote a simple test with only 4 Matrices committed as parameters to a method, and the speed difference to the better "ref"-solution is around 15%!
This is also the way the MS XNA Team recommends!

file attachments

comments

XnaCoder wrote Aug 16, 2007 at 12:05 PM

I did it myself. While it is a speed improvement and should be included into the code, it was not the big speed improvement I hoped for. The engine is too busy with other important stuff, where no Matrices are committed as parameters.

wrote Feb 14, 2013 at 2:57 AM