I don't know if this is the root of the performance issue, but it's not tail recursive optimized, right?