Will recursion hurt performance?

Hi all,

I know that the latest CUDA support recursion.
I am just having concern whether it’s very expansive in terms of performance.

I have a whitted style ray tracer.
And when a ray hits glass surface, I need to spawn both reflected and refracted rays. This can easily be handled with recursion, otherwise I will have to manually build a traverse stack.

So, does using recursive calls hurt peformance?

Yes, recursive calls hurt performance because they cannot be inlined. The overhead of making a true function call (pushing registers onto a stack, jumping, etc) can be significant if the function only performs a small amount of work.

That said, it isn’t obvious that using an algorithm with a manually-managed stack will be much faster than a recursive algorithm. (It might be faster, but I have no direct experience with the technique you are using.) I would try the recursive approach first if it is easier to code.