TraceQL: Improve regexp perf#3139
Conversation
Signed-off-by: Joe Elliott <number101010@gmail.com>
mdisibio
left a comment
There was a problem hiding this comment.
Nice catch. In the upcoming metrics work I ran into a similar problem of needing to do initialization between parsing and evaluation. Ideally we could compile and validate the regexp before the first evaluation because otherwise it will look like a querier or ingester error (since it isn't caught in the query-frontend). We can't do it during parsing because it's hard (impossible?) to return errors through the YACC snippets. Validate is ok but not quite right. So I added an init() method to some AST elements. Not asking for it here, but aligning some ideas.
Yeah, I ran up against these same decisions while making the change. I considered some kind of |
Signed-off-by: Joe Elliott <number101010@gmail.com>
What this PR does:
Fixes a nasty performance issue when regexp matches get to the engine layer. Currently we are calling
regexp.MatchString()which recompiles the regex on every span.Uses benchmarks from this PR against main plus one to highlight the improvement:
{resource.namespace!=""} && {resource.service.name="loki-distributor"} && {duration>2s} && {resource.cluster=~"prod.*"}