Hacker News new | ask | show | jobs
by saagarjha 1242 days ago
The wins from tail calls are generally more from being able to skip the overhead that comes from a function call rather than better branch prediction.
1 comments

It's mentioned in passing at the end of the "the trouble with interpreter loops" section.

A traditional switch/goto loop can thrash the branch predictor. Separating into different tail calling functions gives you more slots and allows the branch predictor to learn relationships between ops.

Not to discount the many other benefits of tail calls.

*Edit: I misspoke slightly, computed gotos can also split the patch jump, but less reliably[0].

[0]https://gcc.gnu.org/pipermail/gcc/2021-April/235891.html