3 ms·
> Since GNU grep passed out of my hands, it appears that use of mmap became non-default, but you can still get it via --mmap. [...] using --mmap can be worth a
by statquontrarian 6y ago
> Since GNU grep passed out of my hands, it appears that use of mmap became non-default, but you can still get it via --mmap. [...] using --mmap can be worth a >20% speedup.
This option was ignored in March 2010 and later removed completely: https://lists.gnu.org/archive/html/grep-commit/2010-03/msg00016.html https://lists.gnu.org/archive/html/grep-commit/2010-03/msg00...
- shakna 6y agoAnd removed for performance reasons, too. > On modern systems, --mmap rarely if ever yields better performance. and > mmap is a bad idea for sequentially accessed file because it will cause a page fault for every read page. Just consider it a failed experiment, and ignore --mmap while accepting it for backwards compatibility.
- burntsushi 6y agoThat 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.)