Skip to content

Commit 21abe85

Browse files
committed
perf(rule_engine,filter): Reuse valuer map from pool
1 parent cc7973d commit 21abe85

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/filter/filter.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"regexp"
2727
"strconv"
2828
"strings"
29+
"sync"
2930

3031
errs "github.com/rabbitstack/fibratus/pkg/errors"
3132
"github.com/rabbitstack/fibratus/pkg/event"
@@ -199,6 +200,7 @@ func (f *filter) RunSequence(e *event.Event, seqID int, partials map[int][]*even
199200
return false
200201
}
201202
valuer := f.mapValuer(e)
203+
defer valuerPool.Put(valuer)
202204
expr := f.seq.Expressions[seqID]
203205

204206
if rawMatch {
@@ -412,12 +414,18 @@ func InterpolateFields(s string, evts []*event.Event) string {
412414
return r
413415
}
414416

417+
var valuerPool = sync.Pool{
418+
New: func() any {
419+
return make(map[string]any)
420+
},
421+
}
422+
415423
// mapValuer for each field present in the AST, we run the
416424
// accessors and extract the field values that are
417425
// supplied to the valuer. The valuer feeds the
418426
// expression with correct values.
419-
func (f *filter) mapValuer(evt *event.Event) map[string]interface{} {
420-
valuer := make(map[string]interface{}, len(f.fields))
427+
func (f *filter) mapValuer(evt *event.Event) map[string]any {
428+
valuer := valuerPool.Get().(map[string]any)
421429
for _, field := range f.fields {
422430
for _, accessor := range f.accessors {
423431
if !accessor.IsFieldAccessible(evt) {

0 commit comments

Comments
 (0)