Why the second search can be faster much than the first time? #2687
-
I have not found any indexing file gererated and just want to know why ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It somewhat depends on the operating system you're using, but generally speaking, all modern operating systems have a cache of the contents of recently read files in main memory. This means that subsequent reads of that file will not actually read from your disk, but from your RAM instead. Reading from RAM is typically much faster (by orders of magnitude, depending on how slow your disk is). Since these days folks tend to have a lot of RAM, even if you're searching a large file or a large code repository, it's plausible that it will fit into your RAM and subsequent searches will be a lot faster. This is also why you don't usually need an index to speed up searches for even sizeable code repositories. Even behemoth code repositories like Chromium fit into memory, and you don't even need a ton of RAM for that to happen. Of course, once you get into proprietary code land, repositories tend to get quite a bit bigger than even Chromium. So even ripgrep might fall over at that point. This is also a common flaw in ad hoc benchmarking. Plenty of folks will run When benchmarking greps, it's typical to focus on the cache case for a few reasons:
So the cached case represents what I believe is the common case and the case where you (as in, the author of a grep) have the most room to impact the final search time. |
Beta Was this translation helpful? Give feedback.
It somewhat depends on the operating system you're using, but generally speaking, all modern operating systems have a cache of the contents of recently read files in main memory. This means that subsequent reads of that file will not actually read from your disk, but from your RAM instead. Reading from RAM is typically much faster (by orders of magnitude, depending on how slow your disk is). Since these days folks tend to have a lot of RAM, even if you're searching a large file or a large code repository, it's plausible that it will fit into your RAM and subsequent searches will be a lot faster.
This is also why you don't usually need an index to speed up searches for even sizeable code r…