Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I had a similar experience, but testing by running `strings` on the Steam Deck repair image (the largest file I had handy) to create a 203 MB strings file with 34,206,436 lines, and then checking it for the string "Steam"

    $ time fgrep -c "Steam" /tmp/steamstrings
    241
    grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.venv,venv  0.09s user 0.03s system 99% cpu 0.112 total

    $ time rg -c Steam /tmp/steamstrings
    241
    rg -c Steam /tmp/steamstrings  0.03s user 0.02s system 92% cpu 0.054 total
    
    $ time ~/source/other/krep/krep "Steam" /tmp/steamstrings
    Found 2226035 matches
    Search completed in 0.0338 seconds (5991.67 MB/s)
    Search details:
      - File size: 202.56 MB
      - Pattern length: 5 characters
      - Using AVX2 acceleration
      - Case-sensitive search
    ~/source/other/krep/krep "Steam" /tmp/steamstrings  0.08s user 0.02s system 225% cpu 0.045 total
So krep is:

1. Extremely fast

2. Extremely inaccurate

3. Not useful if you actually want to see what the lines actually are rather than just knowing how many there aren't

Not to be facetious, but if the goal is to write a program that gives incorrect output as fast as possible I don't think you need to go as far as using AVX2.



I have tried this on a couple of different machines. On one machine it gives ridiculous answers like you found. On the other it at least works as expected, although it's kinda useless since it doesn't print the matched lines.

On the working machine it reported using SSE4.2 acceleration while the broken one used AVX2 acceleration. However, the machine using SSE4.2 didn't see nearly as much speedup as the AVX2 machine. Regular system grep on the SSE4.2 machine took 0.186 seconds to do the search, while krep needed 0.154 seconds. However the biggest test file I had handy was only 123MB, so maybe the lead will grow more with a larger file?


That's probably because pcmpestri is trash for substring search. There is a good reason why ripgrep doesn't use it. :-)

I looked for an authoritative search for why pcmpestri is trash, and I couldn't find anything I was happy linking to other than Agner Fog's instruction tables: https://www.agner.org/optimize/instruction_tables.pdf You can see that the throughput and latency for pcmpestri is just awful.

And yes, not having any code to print the matching lines means that the only code path in krep is just counting things. If that's all your tool is doing, you can totally beat ripgrep or any other tool that is more applicable to generalized use cases. It's why the `memchr` crate (what ripgrep uses for single substring search) has a specialized routine for counting occurrences of bytes (which ripgrep uses for line counting): https://github.com/BurntSushi/memchr/blob/746182171d2e886006...

Because it's faster to do that than it is to reuse the generalized `memchr` API for finding the location of matching bytes.

And counting matches in a multi-threaded context is way easier than actual managing the printing of matches in the same order that you get them.

krep isn't big. You can skim its source code in a few minutes and get a good idea of how it works.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: