Sixteen Bytes at a Time: How Rust Validates UTF-8
Rust’s str validation is word-at-a-time: it reads two usize at a time looking for high bits, so pure-ASCII strings are validated at 16 bytes per iteration instead of one.
Rust’s str validation is word-at-a-time: it reads two usize at a time looking for high bits, so pure-ASCII strings are validated at 16 bytes per iteration instead of one.
Rust’s stable sort implements the powersort merge-tree heuristic from Munro and Wild, with the depth of each merge node computed as the leading zeros of an XOR of scaled midpoints.
For small slices Rust sorts with a fixed branchless sorting network - Dobbelaere’s optimal 13-element network - because mispredicted branches cost more than the extra comparisons.
Rust’s SipHash-1-3 stores its four state words as v0, v2, v1, v3 - a field order chosen so the compiler can auto-vectorise the ARX round into two SIMD lanes.
Rust’s HashMap uses a SwissTable with SSE2 group scanning: one movemask compares 16 control bytes at once, and the top 7 bits of the hash act as a filter before any key comparison.