Definitively Not( James )

2021/05/07


Cloudflare has a really interesting blog post about branch prediction and the cost of if jumps in code. If it’s C, I’m unsure why you’d have non-macro debug if blocks peppered throughout your code, but sometimes it could make sense.


The blog post investigates branch prediciton and how the [Branch Target Buffer][2] affects performance. The TLDR is that once you go above the L1 instruction cache you will find some cost, but in general the cost of an if statement that’s never taken is little to nothing, and the cost of always-taken branches may be an issue.