What Is Tail Call Optimization?
Tail call optimization is a compiler or runtime technique that replaces a call in tail position with a jump that reuses the existing stack frame instead of allocating a new one. As a result, recursion expressed through tail calls runs in constant stack space, much like a loop. Not all languages or modes guarantee it, so its availability varies.
Why it matters
With tail call optimization, recursive code that would otherwise overflow the stack becomes safe and memory-efficient. Its absence is why some languages require loops where others allow deep recursion.
Related guides
What Is a Tail Call?A tail call is a function call that is the last action in a function, allowing the current stack frame to be…
What Is Trampolining?Trampolining is a technique that runs recursive calls as a loop by returning the next step instead of calling…
What Is a Continuation?A continuation represents the rest of a computation at a given point, as a value that can be invoked later to…