3 ms·
You'd get equivalent performance with "goto", but not depend on implicit compiler optimizations to save you from stack overflow. I like the idea of tail calls,
by slver 6y ago
You'd get equivalent performance with "goto", but not depend on implicit compiler optimizations to save you from stack overflow.
I like the idea of tail calls, but I don't like it being an implicit "maybe" optimization of the compiler. Make it part of the standard, make the syntax explicit, and then both hands in.
- haberman 6y agoYou really wouldn't. We tried many approaches, including computed goto, but none of them were able to generate satisfactory code when compared with tail calls: https://gcc.gnu.org/pipermail/gcc/2021-April/235891.html https://gcc.gnu.org/pipermail/gcc/2021-April/235891.html Also, it is not an implicit optimization when "musttail" support is available in the compiler.
- slver 6y agoTailcall optimization is compiled as a JMP, so is goto, so I'm curious where would the difference come from?
- haberman 6y agoThe tail call design gives more control over register allocation, and gets the compiler to generate better code by putting fast paths and slow paths in separate functions. I tried to explain this in the article and in my link upthread.