Ripgrep: How to Make Ripgrep Faster

Updated

Learn how to make ripgrep (rg) searches faster by searching fewer files

Ripgrep: How to Make Ripgrep Faster

Before we start, make sure you have ripgrep installed on your computer. On a Mac, you can install it with Homebrew:

brew install ripgrep

First, open your terminal and navigate to your project folder. To see how much work a search does, add --stats:

rg --stats "pattern"

At the bottom you'll get the number of files searched, the bytes searched and the time it took. The biggest speed-up is searching fewer files, so limit the search to one file type with -t:

rg --stats -t js "pattern"

In my demo project, that took the search from 228406401 bytes and about 32 milliseconds down to under 3,000 bytes and about 3 milliseconds. Use a capital -T to exclude a type instead.

To keep every file type but skip huge files like logs, data dumps or minified bundles, add --max-filesize 1M. And to skip a folder every time, list it in a .rgignore file in your project root:

echo 'fixtures/' > .rgignore

ripgrep reads .rgignore, but Git doesn't, so your .gitignore stays untouched.

undefined

If you don't need a regular expression, add -F to search for the exact text, and avoid --sort path: sorting forces ripgrep to use a single thread.