Show HN: Tacopy – Tail Call Optimization for Python
11 days ago
- #Python
- #Optimization
- #Recursion
- Tacopy is a Python library for optimizing tail-recursive functions by converting them into iterative loops.
- Prevents stack overflow errors by handling deep recursion beyond Python's default limits.
- Offers performance improvements, making functions 1.41x to 2.88x faster than standard recursion.
- Includes validation to ensure functions are properly tail-recursive before transformation.
- Preserves function metadata like docstrings and type hints without runtime overhead.
- Installation is simple with pip or uv, and usage involves decorating functions with @tacopy.
- Demonstrates practical examples including factorial, Fibonacci sequence, GCD, and sum calculations.
- Limitations include module-level functions only, no async support, and requires Python 3.10+.
- Comes with a comprehensive test suite and benchmarks showing significant speedups.
- Open-source under GNU GPL v3.0, encouraging community contributions.