The square root is one of those basic mathematical operations that’s totally ubiquitous in any game’s source code, and yet also has many competing implementations and performance superstitions around it. The compiler offers a sqrt() builtin function, and so do some CPUs, but some programmers insist on writing their own routines in software. And often […]
Archive for the ‘Programming’ Category
I’ve just updated my prior article on virtual function overhead with corrected timing numbers — I hadn’t noticed that my CPU cycle counts were only 32 bits wide so timings of more than 2secs would wrap back around to zero. If you want to run this test on your own hardware, I’ve put my code […]
Whenever I work with virtual functions I find myself wondering: how much is it costing me to perform all these vtable lookups and indirect calls? The usual truism is that computers are so fast now that it doesn’t matter and that the idea of virtuals being a problem is just another myth. Our beloved Xenon […]
For best float-to-int conversion speed, specify the compiler flag /arch:SSE2 to assume the availability of SSE2 opcodes.
The seemingly simple act of assigning an int to a float variable, or vice versa, can be astonishingly expensive. In some architectures it may cost 40 cycles or even more! The reasons for this have to do with rounding and the load-hit-store issue, but the outcome is simple: never cast a float to an int […]
Branching on floating-point values can be a significant performance penalty. In some cases, using the ternary operator ?: or substituting a conditional-move operator like fsel allows you to make your function branchless and run much faster.
Non-desktop platforms don’t have paged memory. If the application exhausts memory, it dies.
The lack of paged memory means that memory fragmentation can kill an application.
Therefore, game applications cannot leak memory. Ever. Period.
In the realm of “things I really wish I had paid more attention to while we were crunching on Left 4 Dead“, I’ve recently been going through the talks from last June’s Gamefest. There is a lot of really great stuff in there, and I’ve only skimmed through a few of them so far, but […]
David R. Martin of Boston College made this great webpage demonstrating eight sorting algorithms and their performance under best-case, worst-case, and average-case conditions. It’s a clever, elegant way to show how there is no such thing as “one best sorting algorithm”, but that each has its own advantages and disadvantages depending on the expected data and […]
Here’s a clever take on the program-the-robot game that does a nice job of teaching of how to think in terms of subroutines and perform instruction-space optimization — in this case the speed-space tradeoff definitely favors space. It feels a lot like programming shaders!