In addition to the debugging and recompilation tips supplied by others above, I would recommend perhaps taking a look at the recursion algorithm itself - It may be more efficient to unroll the recursion employing a stack over which to iterate. For this task, you may find the threads Turning a recursive function into an iterator and Unrolling recursion of interest.