r/programming 1d ago

Branch‑Avoidant Programming

https://easylang.online/blog/branchless
231 Upvotes

87 comments sorted by

View all comments

138

u/meamZ 23h ago

You don't actually need to avoid branches, you just need to make sure that most of the ones you have are very predictable, then their impact is not that big... Same with memory accesses and most other things... The more predictable, the better...

74

u/jdehesa 23h ago

To be fair, the first line of the article says "avoiding branch mispredictions", which is more accurate. But yea, even in their example, if the data happens to be sorted it may be perfectly fine.

8

u/Nicksaurus 16h ago

As always, the real answer is to know your data and optimise for it