---
title: "Don’t stop early: Case-folding source code at memory speed"
description: "GitHub's Blackbird code search case-folds every byte of 480TB of source, and the fastest ASCII path came from removing the early exit at the first non-ASCII byte."
url: "https://swe.quest/articles/don-t-stop-early-case-folding-source-code-at-memory-speed-d9a0d3aa3df1f3f4"
canonical: "https://github.blog/engineering/architecture-optimization/dont-stop-early-case-folding-source-code-at-memory-speed/"
source: "GitHub Engineering"
published: "2026-07-31"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 18
tags: ["performance","rust","search","algorithms","data-structures"]
---

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

A post on [GitHub Engineering](https://swe.quest/sources/github.md), published 2026-07-31, 18 min read, Deep dive. Original: [https://github.blog/engineering/architecture-optimization/dont-stop-early-case-folding-source-code-at-memory-speed/](https://github.blog/engineering/architecture-optimization/dont-stop-early-case-folding-source-code-at-memory-speed/)

## Summary

GitHub's Blackbird code search case-folds every byte of 480TB of source, and the fastest ASCII path came from removing the early exit at the first non-ASCII byte. A branchless sweep that ORs bytes into an accumulator and lowercases arithmetically lets LLVM vectorize to over 45 GiB/s on an Apple M4, versus 3.1 GiB/s for the naive break loop. A two-pass chunked scan reaches about 23 GiB/s, and branchless code without vectorization is actually slower. The open-source Rust crate casefold also avoids heap allocation by reusing the input buffer. For non-ASCII text, it rejects non-folding characters with a 64-code-point page bitmap read straight from UTF-8 lead bytes, and run-length/stride-encoded fold ranges shrink Unicode's 1484 simple folds to 1776 bytes.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)

## Prerequisites

- UTF-8 encoding ([easy posts on Video & media](https://swe.quest/tags/video-media.md?difficulty=easy))
- SIMD vectorization basics
- Rust strings and unsafe pointers ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- branch prediction

## Keywords

casefold, Blackbird, Unicode CaseFolding.txt, LLVM, NEON, ripgrep, GitHub code search

## Related posts

- [Rope Optimizations, Part 1](https://swe.quest/articles/rope-optimizations-part-1-32023b24da3832be.md): Zed · 2024-11-18 · Medium · 10 min read · Data structures, Performance engineering, Rust, Algorithms
  Zed's Rope, a SumTree of 128-byte chunks, sped up offset-to-point translation by storing u128 bitmasks per chunk marking newlines, char boundaries and UTF-16 widths, replacing a per-character loop.
- [The technology behind GitHub’s new code search](https://swe.quest/articles/the-technology-behind-github-s-new-code-search-7c9e939ab132b5db.md): GitHub Engineering · 2023-02-06 · Medium · 13 min read · Search, Rust, System design, Scaling, Data structures
  GitHub built Blackbird, a Rust code search engine, because general text search engines handled punctuation, regex, and GitHub's scale poorly, and brute-force grep would yield about 0.01 QPS.
- [Copy Hunting](https://swe.quest/articles/copy-hunting-7c2f19f97f1f7edc.md): TigerBeetle · 2023-07-26 · Medium · 11 min read · Zig, Compilers, Performance engineering, Debugging, Developer tools
  Reading Zig's emitted LLVM IR as plain text and grepping it is a practical substitute for staring at disassembly when chasing implicit memcopies and binary bloat.
- [More Than 2x Faster Hashing in ClickHouse Using Rust](https://swe.quest/articles/more-than-2x-faster-hashing-in-clickhouse-using-rust-404bde5cc500d24b.md): ClickHouse · 2022-10-25 · Medium · 5 min read · Rust, C & C++, Build systems, Performance engineering, Cryptography
  ClickHouse added optional Rust library support to its C++/CMake build using Corrosion-rs, with BLAKE3 as the first library, exposed to C++ through a Rust shim function using C-compatible FFI types and a header file.
- [A brief history of code search at GitHub](https://swe.quest/articles/a-brief-history-of-code-search-at-github-ac152c8901d98c95.md): GitHub Engineering · 2021-12-15 · Medium · 13 min read · Search, Scaling, Developer tools
  GitHub's code search evolved from a public-only Solr index plus \`git grep\` for private repos, to a decade-long Elasticsearch deployment that grew to 162 nodes, 1.25PB of storage and over 53 billion indexed files.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
