Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It seems generators and trampolines involve considerably more CPU overhead in the 6.x series vs. 5.x, while tail calls are now fully optimized and/or the default stack limit has grown considerably.

Try running the following script with v5.12.0 and again with v6.6.0:

https://gist.github.com/michaelsbradleyjr/d1b104137e8e00468d...

   node --version && node --use_strict ./mutrec_vs_tramp_vs_gen.js


> tail calls are now fully optimized

Can't remember where I heard this, but I'm given to understand they aren't optimized, just allowed. As in, recursive calls from tail position won't be super-fast or anything, they just won't blow out the call stack. Optimization may or may not be added to the engine at some future date.


> while tail calls are now fully optimized and/or the default stack limit has grown considerably

That is great to hear. Now we can finally start really doing functional programming in JS. Too bad about the generators, though.


Well, I'm not sure which one is the case, sorry to say (TCO or bigger stack limits, or both). I was only taking a guess as to why the mutual recursion example works for very large values in node v6.x but not in v5.x. But yes, if tail call optimization is guaranteed, then functional programming patterns can certainly shine the brighter for it.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: