GitHub Blog
Read post

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

GitHub engineers explain how they achieved >45 GiB/s case-folding throughput for their Blackbird code search engine, which indexes 480TB of source code. The key insight is counterintuitive: removing an early-exit branch (that stopped at the first non-ASCII byte) and making the loop entirely branch-free enables LLVM to auto-vectorize it, yielding a 15x speedup over the naive approach. The post details the full design: a branch-free ASCII sweep using byte-space arithmetic, a compact 1776-byte Unicode lookup table using a page bitmap and run-length encoding, and a novel decode-free fold technique that performs UTF-8 case folding as direct byte arithmetic without ever decoding to a code point. The result is open-sourced as the 'casefold' Rust crate.

    #performance#rust
Jul 31•22m read time•From github.blog
Post cover image
Table of contents
Folding is not lowercasingThe counterintuitive core: Don’t stop earlyAvoiding the heapMaking Unicode cheap tooFoldable code points cluster into 64-code-point “pages”Within a page, folds come in runsA run record is two clean bytesFolding is a little-endian byte additionThe ASCII shortcut in the tail loopPutting it together: the whole tableWhere it lands against the alternativesTake this with youTags:Written by
4.2K Impressions
GitHub Blog's image
GitHub Blog

The GitHub Blog provides updates, announcements, and insights from the world's leading software deve...

1.4K Followers

•

3K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard