Re:Don’t underestimate grep-based code scanning
by fragsworth on Wednesday August 07, 2019 @11:52AM
(#20635837)
Another thing that's not immediately obvious is the longer your search string is in grep, the faster it will find your results.
[ Parent
| on HN ]
Re:Don’t underestimate grep-based code scanning
by herpderperator on Wednesday August 07, 2019 @03:19PM
(#20637938)
Can you explain why that's the case?
Re:Don’t underestimate grep-based code scanning
by saghm on Wednesday August 07, 2019 @03:27PM
(#20638002)
I think it's because there are fewer potential substrings to check for matches, since most of the characters you add to a regex to make it longer also add to the minimum length of the expressions that it can find
Re:Don’t underestimate grep-based code scanning
by jlebar on Wednesday August 07, 2019 @03:30PM
(#20638039)
String search algorithms can cleverly skip forward when they don't find a match. They can skip forward more for longer "needle" strings.
That said grep is pretty fast period, so probably doesn't make a huge difference in practice, especially if you're IO-bound, which is common.
Re:Don’t underestimate grep-based code scanning
by jandrese on Wednesday August 07, 2019 @03:48PM
(#20638177)
The caveat being if you're Unicode aware then many of the old skipahead strategies don't work as well and have to be rolled back or disabled.
Re:Don’t underestimate grep-based code scanning
by burntsushi on Wednesday August 07, 2019 @04:09PM
(#20638392)
That's not true. They work just fine. Typically, substring search algorithms are implemented at the encoding level, e.g., on UTF-8 directly. If you just treat that as an alphabet of size 256, then algorithms like Boyer-Moore work out of the box.
But the skip-ahead stuff isn't the most important thing nowadays. The key is staying in the fast vectorized skip loop as long as possible.
Re:Don’t underestimate grep-based code scanning
by jandrese on Wednesday August 07, 2019 @04:12PM
(#20638424)
I noticed severe slowdowns when passing in the /u flag on my regexes, even with big fixed ASCII strings in the middle of the patterns. They were taking 10 times as long to complete.
Re:Don’t underestimate grep-based code scanning
by burntsushi on Wednesday August 07, 2019 @04:43PM
(#20638804)
That doesn't imply that things like Boyer-Moore suddenly stop being effective. Without more details (which regex engine? what regex? what corpus? which programming language?) it's impossible to state the cause, but it could be as simple as the regex engine not being smart enough to use a literal searcher in that case.
Re:Don’t underestimate grep-based code scanning
by JetSpiegel on Wednesday August 07, 2019 @07:01PM
(#20640108)
Since you don't want to toot your own horn, and you saved me many hours of not waiting for searches, I'll link to ripgrep here