3 ms·
Could someone clarify the example where an unlikely fallback path is wrapped in a musttail? My understanding is that musttail is useful because it prevents sta
by highfrequency 2y ago
Could someone clarify the example where an unlikely fallback path is wrapped in a musttail?
My understanding is that musttail is useful because it prevents stack frame construction and register spilling; the calling function basically says "you can re-use the existing stack and not worry about my local variables."
But doesn't the stack frame construction overhead / register spilling only occur when the fallback path is actually invoked; therefore if it is unlikely and you care less about performance in this slow path it doesn't matter if you wrap the fallback path in musttail?
(Is this purely a branch prediction effect, where the possibility of extra work needing to be done slows down the fast path even when the work does not need to be done?)
- fweimer 2y agoIf the fallback path can be invoked repeatedly for one message (depending on message size), the tail call is a correctness issue because your stack is probably not going to be large enough to keep all the fallback path frames.