Open-Source Wikis

/

ripgrep

/

Fun facts

BurntSushi/ripgrep

Fun facts

Small interesting things found while reading the ripgrep source.

The oldest comment in the binary

The first commit was on 2016-02-27, but a fun comment shipping today is the doc-comment on fn main() in crates/core/main.rs:

/// Then, as it was, then again it will be.
fn main() -> ExitCode {

It is a Yes lyric (from "Roundabout"), and it has survived multiple rewrites of the entry-point logic. The comment is older than libripgrep, older than the workspace reorganisation, and older than the Flag trait. Also: appropriate for a function whose body keeps getting refactored back to roughly the same shape.

The largest single file

crates/core/flags/defs.rs is 7,779 lines and ~235 KB. It contains a struct + Flag trait implementation for every one of ripgrep's CLI flags (over 100 of them), each carrying its short doc string, long doc string (in mdoc/mdoc), category, optional negation, optional aliases, and an update method. Adding a new flag almost always means adding to this file. The CHANGELOG for 14.0.0 says this file replaced ripgrep's clap dependency entirely.

The smallest crate

The grep crate (crates/grep/src/lib.rs) is 6 lines of actual code:

pub extern crate grep_cli as cli;
pub extern crate grep_matcher as matcher;
#[cfg(feature = "pcre2")]
pub extern crate grep_pcre2 as pcre2;
pub extern crate grep_printer as printer;
pub extern crate grep_regex as regex;
pub extern crate grep_searcher as searcher;

It exists purely as a facade so external Rust applications can depend on grep instead of pulling each library crate individually.

The musl jemalloc swap

ripgrep links tikv-jemallocator only on 64-bit musl Linux. The reasoning, captured in the comment block above the #[global_allocator] declaration in crates/core/main.rs, is: glibc's allocator is fine, jemalloc is fine, but musl's allocator is "substantially worse" because musl prioritises being small and amenable to static compilation. So the static-musl release binary swaps in jemalloc to recover performance. Glibc and macOS just use the system allocator.

"If --quiet and --files-without-match, the exit code was wrong"

A 15.0.0 bug fix entry (BUG #3108) reads:

Fix a bug where -q --files-without-match inverted the exit code.

This is the kind of bug that only matters once. But once you learn that two CLI flags can interact to flip the program's exit code, every subsequent flag combination feels like a landmine. ripgrep's regression test suite (tests/regression.rs) is filled with similarly-titled tests, each named with the issue number that triggered it.

The "DEPRECATED" feature flags that don't do anything

crates/grep/Cargo.toml still declares:

# These features are DEPRECATED. Runtime dispatch is used for SIMD now.
simd-accel = []
avx-accel = []

Both features were removed in ripgrep 14.1.1 (Sep 2024). The empty feature declarations remain so that downstream Cargo.toml files passing --features simd-accel continue to compile. The actual SIMD dispatch happens at runtime inside the underlying regex crate; ripgrep itself doesn't need build-time toggles for it any more.

Lyrics-as-comments

The Yes lyric in main.rs isn't unique. There are music references and dry quips scattered through the tests in tests/feature.rs and tests/regression.rs, often used as test-case haystacks. The Sherlock-Holmes paragraph in tests/hay.rs::SHERLOCK is the most famous; it appears in essentially every cookbook example in the documentation.

TODO/FIXME/HACK count

A grep across the entire workspace (grep -rE "TODO|FIXME|HACK" --include="*.rs") finds 10 occurrences total. Eight of those are in tests/regression.rs and describe known-but-not-yet-fully-characterised bug behaviour. The library crates have effectively zero accumulated technical-debt comments.

For context, this is well below typical repository TODO densities. Andrew Gallant either doesn't write TODOs or files them as GitHub issues instead.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Fun facts – ripgrep wiki | Factory