Skip to content
Latchkey

What Is Trampolining?

Trampolining is a pattern where a function, instead of calling the next step directly, returns a value describing that step, and a top-level loop called the trampoline repeatedly invokes the returned steps. Because each step returns before the next runs, the stack never grows with the depth of recursion. It simulates tail call optimization in environments that lack it.

Why it matters

Trampolining lets deeply recursive or mutually recursive code run safely where the runtime does not optimize tail calls. The price is some overhead and a less direct control flow.

Related guides

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