r/javascript • u/fagnerbrack • Jul 20 '26
Your Recursion Is Lying to You
https://blog.gaborkoos.com/posts/2026-05-09-Your-Recursion-Is-Lying-to-You/
0
Upvotes
r/javascript • u/fagnerbrack • Jul 20 '26
View all comments
Show parent comment
7
u/azhder Jul 20 '26 edited Jul 20 '26
It is not optimization if the difference is the code always works VS the code doesn't always work. Optimization is the code always works, but faster and/or with smaller memory footprint.
The name is Proper Tail Calls. It was supposed to replace stack and actual function calling function with a (set of) loop(s). And it worked. The only reason why it was removed is that big companies complained their stack traces were no longer the same. So people making V8 started asking for an explicit invocation and started calling it "optimization" to minimize the significance of them not following through with the standard. They asked the standard be changed.
It is not an optimization. An optimization would have been making better stack traces after it was implemented, making them more readable, faster, less memory to keep track of the "invocations" that were replaced with loops under the hood.