- Filtering a slice of numbers by a threshold shows performance varying by selectivity, with 50% being slowest due to branch mispredictions.
- The branch predictor guesses which path to take; unpredictable data causes mispredictions, which are costly (15–20 cycles each).
- Sorted input makes the branch predictable (4.5x faster), but sorting is not a practical fix.
- Branchless programming removes the unpredictable branch by always writing elements and using comparison results as numbers to conditionally advance a cursor.