Cache compiled regular expressions in the log buffer

This change keeps each compiled regular expression in a cache in the
log buffer. The cache size is not more than the number of patterns
given to Match.

This change removes the TODO in log_buffer.go.
This commit is contained in:
Veer Singh
2026-07-20 16:12:36 -07:00
parent 059959141d
commit be4034f35a
2 changed files with 25 additions and 5 deletions
+14
View File
@@ -108,3 +108,17 @@ func TestMatch(t *testing.T) {
}
}
}
func BenchmarkMatch(b *testing.B) {
buf := NewLogBuffer(10)
for i := 0; i < 10; i++ {
buf.Push(&types.Log{Message: "Out of memory: Kill process 20744 (mysqld) score 318 or sacrifice child"})
}
// A pattern from the default kernel monitor configuration which does not
// match the buffered logs.
expr := `task [\S ]+:\w+ blocked for more than \w+ seconds\.`
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf.Match(expr)
}
}