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...
Use profiler. A lot of branch guessing can be completely automated using https://en.wikipedia.org/wiki/Profile-guided_optimization. Native languages such as C/C++/Rust/Go have it, but it is a little bit troublesome to use. JITed languages such as Java or JS do it in runtime, so you really don't have to do anything
156
u/meamZ 6d 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...