NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Removing recursion via explicit callstack simulation (jnkr.tech)
juancn 1 days ago [-]
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 1 days ago [-]
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.
kinow 21 hours ago [-]
It is common in Python too. Reduces memory and eliminates stack errors in some cases. Althoughin Python I think the developer always needs to implement it and cannot rely on compiler/interpreter to optimize that.
1 days ago [-]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 11:06:57 GMT+0000 (Coordinated Universal Time) with Vercel.