Quote:Original post by cpiasminc
I fail to see how this disputes that recursion is bad performance-wise.
First of all, traversing a KD tree doesn't need recursion. It can be done iteratively by pushing the far node to a stack if it needs to be traversed later. Havran's PhD thesis demonstrates the algorithm very simply.
Second, accessing memory randomly is a far greater expense than the cost of recursion. An L2 cache miss is about 500 cycles, while setting up a stack frame and branching is like 30 (since the stack is almost never an L2 miss). The real enemy is memory latency in every case. There are no 'bad algorithms' just 'bad implementations'.
For instance, an enterprising PS3 developer might break his KD tree into self-contained 4kb pages that can be prefetched to the SPE, and the entire tree traversed with almost zero latency penalty. Next Gen Engine design is all about algorithms that employ predictable fixed-footprint memory access with very minimal indirection.