Skip to content
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

Cache optimized regexp matchers #465

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added BenchmarkNewFastRegexMatcher_CacheMisses
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Mar 30, 2023
commit 6cc5933c33fd23a31e88eb94227e19e057926b6c
17 changes: 17 additions & 0 deletions model/labels/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -108,6 +109,22 @@ func BenchmarkNewFastRegexMatcher(b *testing.B) {
b.Run("without cache", runBenchmark(newFastRegexMatcherWithoutCache))
}

func BenchmarkNewFastRegexMatcher_CacheMisses(b *testing.B) {
regexpPrefix := strings.Repeat("x", 20)

for n := 0; n < b.N; n++ {
// Generate unique regexps. These regexps are very simple to simulate
// a worst case scenario in case of cache misses (the cost of looking up
// the cache may be higher than not having a cache at all).
regexp := regexpPrefix + strconv.Itoa(n)

_, err := NewFastRegexMatcher(regexp)
if err != nil {
b.Fatal(err)
}
}
}

func TestOptimizeConcatRegex(t *testing.T) {
cases := []struct {
regex string
Expand Down