« All posts

Microsoft's tgrep: Trigram-Indexed grep in Rust, Up to 52x Faster

Microsoft's tgrep brings trigram-indexed, client/server grep to Rust, delivering up to 52x faster searches than ripgrep on large repos.

tgrep is a Rust tool from Microsoft that speeds up regex search across large codebases by pre-building a trigram index and running a persistent server, instead of scanning every file on each query the way grep and ripgrep do. It's already integrated into GitHub Copilot CLI to power repository search.

Benchmarks across repos like gecko-dev, chromium, and linux show tgrep beating ripgrep in 17 of 18 tested platform/repo combinations, with speedups reaching up to 52x. The one exception is a near-tie on Kubernetes under Linux; margins generally narrow when a query returns very large result sets, since delivering the matches then costs more than the index saves in lookup time.

Under the hood, a HybridIndex layers an mmap'd on-disk IndexReader with an in-memory LiveIndex overlay kept current by a file watcher and a parallel background indexer, with periodic flushes to bound memory use. A JSON-RPC TCP server allows multiple clients to query concurrently.

The tool also explicitly handles real-world repo quirks: it warns when .gitignore rules can't apply outside a git repository, respects git's core.ignorecase setting to avoid mis-handling files on case-insensitive filesystems, and requires that indexing and serving flags—like file size caps and exclusions—stay in sync, or files can silently disappear from the served index.

This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work