4 ms·
I can't help but notice that once again tail call optimization seems to be one of the last things added, and even then requires a specific flag to work. Is the
by jarcane 10y ago
I can't help but notice that once again tail call optimization seems to be one of the last things added, and even then requires a specific flag to work.
Is there some reason for this pattern, like actual performance/technical difficulties, or is it more "My Java/C professor said recursion is bad"?
- epmatsw 10y agoFrom my understanding, there's not a lot of performance benefit in most cases and a performance degradation in others. Also there's some reluctance to change the behavior of existing code. Plus a whole bunch of unaddressed debugging issues (what does console.stack show?). https://github.com/tc39/proposal-ptc-syntax https://github.com/tc39/proposal-ptc-syntax
- cpeterso 10y agoAlso, how would script feature detect whether the VM implemented TCO? Code written assuming TCO would still run, but very inefficiently.
- dsp1234 10y agoFor Node.js, define a simple function that does minimal computation, but that would blow the stack if called say a million times[0]. Run that function inside of a new vm context[1]. If it errors with a stack overflow, then no TCO. [0] - function n(x){if(x > 0) n(x-1)} [1] - https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_sandbox_options https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_sa...