Skip to content

SYSTEM Cited by 1 source

casefold (Rust crate)

Definition

casefold is a Rust crate open-sourced by GitHub that performs Unicode simple case-folding at memory-bandwidth speed. It implements the simple (1-to-1) folds from Unicode's CaseFolding.txt (statuses C and S) — not full folds (ß → ss) or Turkic locale folds.

Design

  • ASCII fast path: Branchless sweep of the entire buffer with OR-accumulator for non-ASCII detection. LLVM auto-vectorizes to 16-byte NEON instructions, achieving >45 GiB/s on Apple M4.
  • Non-ASCII path: 1,776-byte lookup table using paged-bitmap + run-length-encoded entries + SWAR byte search. Folds are performed as little-endian byte-space u32 addition — no UTF-8 decode or re-encode.
  • Zero allocation on common path: Takes String by value, mutates in place for ASCII-only or non-folding multibyte text. Second buffer allocated only for the two Unicode outliers that grow in byte length (U+023A, U+023E).

Performance (Apple M4)

Workload Throughput
Pure ASCII (5.7 KB) >45 GiB/s
CJK, no folds (8.1 KB) 2.95 GiB/s
Worst-case all-folding (8.8 KB) 869 MiB/s
Length-changing folds (1.7 KB) 1.26 GiB/s

(Source: sources/2026-07-31-github-dont-stop-early-case-folding-source-code-at-memory-speed)

Availability

Seen in

Last updated · 607 distilled / 1,851 read