News for hackers. Stuff that matters.
Re:Why GNU grep is fast (2010) by burntsushi on Thursday July 23, 2020 @09:50AM (#23927341)
That may have been true back then, but it isn't true today. Or at least, it depends on your OS. On Linux, you can actually run this test fairly reliable with ripgrep. Pick a big file (hundreds of MB or a couple GB), make sure it's on a ramdisk (or in cache) and search for a pattern that doesn't exist:

    $ rg --mmap zqzqzqzq big-file
    $ rg --no-mmap zqzqzqzq big-file
The first is faster on my system by a sizeable portion.

There are cases where mmap can be slower. For example, when searching lots of small files simultaneously. The overhead of managing the memory maps in the OS ends up dominating.

EDIT: Memorys maps also have the downside of being susceptible to SIGBUS if the file it is searching is truncated. In this case, ripgrep aborts. (This is mentioned in the README, and you can avoid this in all scenarios by passing --no-mmap.)

There are no comments on this comment yet.