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
Improved benchmark
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Mar 30, 2023
commit 9c42dde348460ec0466140df6bda47f43f1e9b1e
28 changes: 18 additions & 10 deletions model/labels/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,26 @@ func BenchmarkNewFastRegexMatcher(b *testing.B) {
}

func BenchmarkNewFastRegexMatcher_CacheMisses(b *testing.B) {
regexpPrefix := strings.Repeat("x", 20)
// Init the random seed with a constant, so that it doesn't change between runs.
randGenerator := rand.New(rand.NewSource(1))

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)
tests := map[string]string{
"simple regexp": randString(randGenerator, 10),
"complex regexp": strings.Join(randStrings(randGenerator, 100, 10), "|"),
}

_, err := NewFastRegexMatcher(regexp)
if err != nil {
b.Fatal(err)
}
for testName, regexpPrefix := range tests {
b.Run(testName, func(b *testing.B) {
for n := 0; n < b.N; n++ {
// Unique regexp to emulate 100% cache misses.
regexp := regexpPrefix + strconv.Itoa(n)

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

Expand Down