Skip to content

Does RipGrep optimize queries sharing a common prefix? #2048

Answered by BurntSushi
zachriggle asked this question in Q&A
Discussion options

You must be logged in to vote

Have you read my blog post introducing ripgrep? Literal optimizations of this sort are a central part of what makes ripgrep fast.

Also, by the way you're speaking, it kind of seems like you're assuming that the execution engine has backtracking semantics. I can't say for sure, but that's what it sounds like. Of course, if you use -P/--pcre2, this is a true. But the default engine uses finite automata, so matching an alternation doesn't try Bar and then BarBaz and then Foo one after another. They are all matched simultaneously. Of course, that only occurs when the actual regex engine is used.

Of course, for a simple query like Foo(Bar|BarBaz|Foo), the regex engine shouldn't be used at all.…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@zachriggle
Comment options

@BurntSushi
Comment options

Answer selected by zachriggle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants