-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make *
and +
non-greedy to double regex filter speed.
#4775
Conversation
pkg/logql/log/exec_test.go
Outdated
// Copyright 2010 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a fork of https://github.com/golang/go/blob/master/src/regexp/exec_test.go. I'm not certain we can merge this due to the licensing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is allowed, but I wouldn't bother - one or two examples where you check the string output of allNonGreedy
seems fine as a test; you don't need to re-test the whole regex package.
Why don't you just prepend |
If I'm not mistaken it will make EDIT: I've just ran the benchmark and prepended
The results basically flipped. |
Well that makes me sad. |
pkg/logql/log/exec_test.go
Outdated
// Copyright 2010 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is allowed, but I wouldn't bother - one or two examples where you check the string output of allNonGreedy
seems fine as a test; you don't need to re-test the whole regex package.
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@bboreham would it make sense to patch the |
No I don't expect the Go project would accept that change upstream. Doesn't harm to ask. However I do think we should use a fork of the and I have a couple more in mind. It's a big step to fork something like this, but I think for 20%+ improvement it should be considered. |
Summary:
This patch makes all regular expressions with
*
or+
for filters non-greedy. That means.*
becomes.*?
in each case. E.g. givenfoo_foo_foo
the expressionf.*oo
will match[foo]_foo_foo
while the original version would match[foo_foo_foo]
.This will not affect the results for
Regexp.Match
but would affectRegexp.Find
.