Don't stop early: Case-folding source code at memory speed
Jul 31, 2026Alexander Neubeck, Greg Orzell

Summary
This post details significant performance optimizations for case folding, particularly for ASCII characters, by removing early exits and optimizing for vectorization. It introduces a branchless ASCII folding implementation that achieves memory bandwidth speeds (>45 GiB/s) by eliminating branches and leveraging vectorization. The post also covers efficient handling of Unicode case folding and memory management to avoid unnecessary allocations, including a strategy for allocating a worst-case buffer once for Unicode folds that might increase string length. The open-sourced Rust crate `casefold` implements these optimizations.