Between massive log files and big code bases, if you’re a developer, there’s a good chance you spend a lot of time searching.
grep is typically the old standby here. I know I’ve used it just about every day for as long as I can remember.
However, there’s a new kid on the block that goes by the name of
ripgrep (executable as
rg) that’s really stirring things up. Let me show you what there is to like about
ripgrep’s main attraction is that it’s crazy fast.
Most of my development work is done with the Magento platform. A vanilla installation of Magento Enterprise Edition v188.8.131.52 is…
With Magento 2, the code base has more than doubled. Vanilla Magento Enterprise Edition v2.1.3 is…
Even when the files are cached in memory, searching the entire Magento code base with
grep -r feels slow. However, with
ripgrep it feels instant.
I did some benchmarking to find out just how much faster
ripgrep is. Here’s a comparison of the amount of (clock) time it takes to search for “isStraight” across the entire Magento code base with
ripgrep as compared to
grep -r on my MacBook with the files in cache.
As you can see
ripgrep is more than 10 times faster searching through both the Magento 1 and 2 codebases.
When the files being searched are not in cache (e.g. searching the files for the first time), the savings are not as drastic. The overhead in this case is not searching, but rather reading from disk. Still,
ripgrep will save you a bit of time in this case. Here’s a comparison of the same search with a cool cache.
ripgrep is not intended to be a drop in replacement for
grep. A few things are of note here…
ripgrep searches recursively by default. You do not need to supply any additional flags (such as
By default it will not search any thing that is ignored via
.gitignore. This can be a blessing or a curse. To override this behavior you can use the
ripgrep does not print its results in the same format as
grep -r. It uses syntax highlighting by default. It also print all matches for a single file underneath the file name with line numbers
This means you won’t be able to just replace
rg for your
I hope some of you found this article interesting and useful. There are certainly other things of note regarding
ripgrep that I have not covered, so I encourage you to read through the README and this blog post by the tool’s author to learn more.
If you have any questions or comments, feel free to drop a note below, or, as always, you can reach me on Twitter as well.
Hi, I'm Max!
If you'd like to get in touch with me the best way is on Twitter.