TGB Trig Optimizations
by Chris Egerter · in Technical Issues · 11/15/2007 (2:40 pm) · 3 replies
#2
11/15/2007 (2:50 pm)
Quote:It is not creating a new t2dVector, it is returning a reference to itself so that you can do things like this:
inline t2dVector& operator /= (const F32 s) { mX /= s; mY /= s; return *this; };
Does anyone see the point of returning *this? It creates a new t2DVector for every operation and then never uses it. Tons of cycles wasted on vector operations everywhere throughout the engine!
if( ( someVec /= 4.0f ).isLenZero() ) // do stuff
#3
i would be inclined to not do these checks because:
* the code becomes harder to trust & maintain, in exchange for not much optimization.
* the underlying libraries and/or FPU should already be doing this, possibly more efficiently.
* branch statements (conditionals) make it difficult for the modern CPU to pipeline efficiently, and so executing a simple if() statement may in fact mean greater overall cost than simply going ahead and performing the seemingly more expensive operation every time. - i'm not sure that's necessarily the case here, but it's something to bear in mind when optimizing at this level.
11/15/2007 (4:02 pm)
Re checking for 0 and other special angles,i would be inclined to not do these checks because:
* the code becomes harder to trust & maintain, in exchange for not much optimization.
* the underlying libraries and/or FPU should already be doing this, possibly more efficiently.
* branch statements (conditionals) make it difficult for the modern CPU to pipeline efficiently, and so executing a simple if() statement may in fact mean greater overall cost than simply going ahead and performing the seemingly more expensive operation every time. - i'm not sure that's necessarily the case here, but it's something to bear in mind when optimizing at this level.
Associate David Montgomery-Blake
David MontgomeryBlake