Branchless Rust: Making a Filter 4x Faster by Removing an if
SMRTR summary
Branch misprediction — not memory allocation — is why a simple filter runs slowest at 50% selectivity on random data. When data is unpredictable, the CPU's branch predictor fails half the time, costing 15–20 cycles per miss. Replacing the conditional write with unconditional writes and pointer arithmetic eliminates the branch entirely, making the worst case nearly 4x faster.
SMRTR provides this summary for quick context. The original article belongs to lobste.rs.
Read the original article