Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →