3 ms·
Most optimizations only offer constant factor improvements. Tail call optimization is the difference between O(1) and O(N) stack size.
by haberman 4y ago
Most optimizations only offer constant factor improvements. Tail call optimization is the difference between O(1) and O(N) stack size.
- phkahler 4y agoTail calls can be optimized at the source code level too. When I first read about them decades ago I thought it was a stupid notion due to me not understanding how a good compiler can optimize them away. Then I wondered why certain people felt the need to write code that way. I still wonder that.
- haberman 4y agoI wrote an article about my motivation for it: https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html https://blog.reverberate.org/2021/04/21/musttail-efficient-i...
- phkahler 4y agoThanks for that. Having written a threaded interpreter before that immediately made sense. It does seem like you used some other hints to the compiler as well so this would fall under "experts only" type of code and that's OK. I still wonder how well good old "goto" might do, but once you move away from a huge switch/case to individual functions I can see how it might help a bit. I still don't understand why some people seem to like the idea of iterating simpler things with recursion using a tail call.