December 5, 2025
Bounce house of recursion
Show HN: Tacopy – Tail Call Optimization for Python
Python’s stack saver or just a shiny trampoline? HN can’t agree
TLDR: Tacopy rewrites certain self-calling Python functions into loops to prevent stack crashes and speed them up. The crowd split between “finally, a practical fix” and “just use a tiny trampoline,” with open questions about complex cases like mutually recursive functions and wishes for nested-function support.
Show HN dropped Tacopy, a decorator that quietly rewrites certain recursive Python functions into simple loops so they don’t crash with deep calls. Translation for non-nerds: it takes a function that calls itself over and over and, under the hood, turns it into a basic “do it again” loop to avoid a stack overflow. Claims of speed gains and “no runtime overhead” had folks cheering—until the comment section went full soap opera.
The “I’ve seen the stack explode in production” crowd, like anilakar, praised the escape hatch, calling overflows an inevitability and admitting refactoring to loops was a hassle. Meanwhile, the minimalists showed up with pitchforks: phplovesong asked why anyone needs a library when a tiny “trampoline” wrapper (a common DIY technique) does the job, sparking a “tool vs two-liner” showdown. srean pushed the edge case drama: can it handle mutually recursive calls (function A calls B and B calls A)? That’s where many use tail calls, and the room got quiet. Feature wishlist? javierbg95 wants support for nested helper functions to keep public APIs clean, while dkersten dropped nostalgia about trying this at the bytecode level back in the Python 2 era.
In short: excitement, skepticism, and trampoline jokes galore. Tacopy turned Hacker News into a bounce house—with loops
Key Points
- •Tacopy provides a decorator that transforms tail-recursive Python functions into iterative loops using AST rewrites.
- •It prevents recursion-limit errors and claims 1.41x–2.88x performance gains over standard recursion.
- •Optimization occurs at decoration time with no runtime overhead and preserves function metadata.
- •Functions must be module-level, fully tail-recursive, and non-async; otherwise a TailRecursionError is raised.
- •Examples (factorial, Fibonacci, GCD, summation) and a show_transformed_code utility are provided for usage and debugging.