GitHub has released a new open-source Rust crate called `casefold`, designed to perform case folding operations at memory speed. This crate is a result of optimizations made for Blackbird, GitHub's code search engine, which indexes over 180 million repositories. Case folding is crucial for matching text where case distinctions should be ignored, such as in search queries, regular expressions, and identifiers like usernames or hostnames.
The crate highlights the difference between case folding and lowercasing. Lowercasing is intended for display and is locale- and context-sensitive, while case folding is for comparison and is deliberately context-free and locale-independent. Using lowercasing for comparison can lead to incorrect matches due to variations in characters like 'ß', 'İ', or the Greek final sigma. The `casefold` crate implements simple (1-to-1) folds as defined in the Unicode Character Database's CaseFolding.txt, consistent with other tools like ripgrep.
A key optimization in the `casefold` crate involves a counterintuitive approach for ASCII text. Instead of stopping early at the first non-ASCII byte, the crate sweeps the entire buffer with no branches. This method was found to be faster for the predominantly ASCII source code processed by GitHub's search engine, significantly improving performance for a fundamental operation that is executed billions of times.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
GitHub has open-sourced a Rust crate named `casefold` that optimizes case folding for text comparison, particularly for its Blackbird code search engine. This development improves the speed and accuracy of case-insensitive matching in large codebases by implementing a branchless approach for ASCII text and distinguishing case folding from lowercasing.