# Don’t stop early: Case-folding source code at memory speed

[Github](https://yomu.fyi/company/github) · Alexander Neubeck · Jul 31, 2026

**Type:** Problem & solution

## Summary

GitHub's code search engine, Blackbird, must case-fold over 480TB of source code across 180 million repositories during indexing and query matching. To accelerate this operation on source code that is overwhelmingly ASCII, the engineering team replaced early-exit branching with an unconditional branch-free loop. The implementation tests uppercase ASCII ranges using wrapping arithmetic, modifies bits in place, and detects non-ASCII bytes with an accumulator register tested only after the loop completes. Eliminating data-dependent exits allowed LLVM to generate SIMD instructions and achieve throughput exceeding 45 GiB/s on an Apple M4 processor. The optimized implementation was released as the open-source Rust crate casefold.

## Context

GitHub's code search engine, Blackbird, indexes over 180 million repositories totaling more than 480TB of source code, requiring every byte to be case-folded during ngram indexing and query matching.

## Approach / What changed

Eliminating early loop exits and conditional branches in the ASCII fast path in favor of wrapping byte arithmetic, bitwise mutations, and an OR accumulator to enable full compiler vectorization, while handling Unicode reallocations with an exact worst-case growth bound.

## Takeaways

- Data-dependent loop exits prevent compiler auto-vectorization, so sweeping an entire buffer unconditionally can run substantially faster than breaking early on non-ASCII bytes.
- Branchless writes act as a pessimization in scalar execution due to unnecessary memory stores, but they become highly profitable when they enable compiler vectorization into single SIMD instructions.
- Simple Unicode case folding can expand UTF-8 character length because two-byte characters like U+023A and U+023E fold into three-byte characters, capping maximum output growth at 1.5 times the input length.

**Tags:** [Open Source](https://yomu.fyi/topic/open-source), [Performance](https://yomu.fyi/topic/performance), [Rust](https://yomu.fyi/topic/rust), [Search](https://yomu.fyi/topic/search)

[Read original post](https://github.blog/engineering/architecture-optimization/dont-stop-early-case-folding-source-code-at-memory-speed)
