3 ms·
> If the recursion can be tail called optimized then yes the loop is the optimized performant implementation. Is it? My mental model of tail-call optimization
by sokoloff 4y ago
> If the recursion can be tail called optimized then yes the loop is the optimized performant implementation.
Is it? My mental model of tail-call optimization is that it’s just a replacement of the stack variable values in place and a jump to the function entry point (which seems like the same amount of work as updating local variables in a loop and jumping to the head of the loop).