r/programming 1d ago

Branch‑Avoidant Programming

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

87 comments sorted by

View all comments

3

u/tomysshadow 11h ago

This is one of those optimizations that do truly exist but you really really need to profile to know if it's actually improving anything. You cannot just start writing branchless code everywhere on the assumption that it will speed up your code, because it often has the potential to make it slower depending on the specific circumstances.

(Sorry if that's, like, super obvious, but I just think it's worth emphasizing.)

Write the basic version using if statements first. Do this stuff if it results in code that is actually too slow.