Removing recursion via explicit callstack simulation

gsky 12 points 2 comments March 10, 2026
jnkr.tech · View on Hacker News

Discussion Highlights (2 comments)

juancn

It can be done mechanically, it's essentially what a compiler does. But yeah, it can be a useful technique, specially when there's tail recursion and the explicit stack just vanishes and the recursion turns into a plain old loop which the hardware just loves.

Panzerschrek

While coding recursive algorithms in C++ and Rust I have found, that they have some overhead due to performing recursive calls. Compilers can't inline such calls (with exception of tail-recursion). So, replacing recursion with manually-managed stack gives some performance boost. I am wondering why no major C++ compiler can do this for me automatically.

Semantic search powered by Rivestack pgvector
3,471 stories · 32,344 chunks indexed