regexp: fast path for prefix/suffix literals matching on anchored regexps #39869
Labels
Milestone
Comments
As an extension the regexp does not even need to be anchored. Some overuses of regex I have seen are just matching a constant string which can usually optimized by using |
Yeah, I think this would be addressed through a combination of #21743, and Russ's first suggestion in #21463 (comment). I think in the case of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To my understanding, currently there's no fast path for anchored regular expressions starting/ending with a literal, like
^something.*$
or^.*something$
. I'm wondering if you have considered adding a specific optimisation for this use case.Use case
I'm raising this issue, because in Prometheus we do a large use of anchored regexps (for labels matching) and having prefix/suffix literals in the regex looks to be quite a common use case.
In past few days I've worked on a small optimization in Prometheus (PR) to detect safe cases when we can circuit break the regex matching with a
strings.HasPrefix()
andstrings.HasSuffix()
, and it showed to bring significant benefits for our specific use case.The text was updated successfully, but these errors were encountered: