lib/streamaggr: reduce the number of pointers at "total" aggregation state

This should reduce load on GC when scanning heap objects.
This commit is contained in:
Aliaksandr Valialkin 2024-03-04 17:43:49 +02:00
parent d42667fc41
commit b232968bb4
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -34,7 +34,7 @@ type totalAggrState struct {
type totalStateValue struct {
mu sync.Mutex
lastValues map[string]*lastValueState
lastValues map[string]lastValueState
total float64
deleteDeadline uint64
deleted bool
@ -74,7 +74,7 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
if !ok {
// The entry is missing in the map. Try creating it.
v = &totalStateValue{
lastValues: make(map[string]*lastValueState),
lastValues: make(map[string]lastValueState),
}
vNew, loaded := as.m.LoadOrStore(outputKey, v)
if loaded {
@ -87,10 +87,6 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
deleted := sv.deleted
if !deleted {
lv, ok := sv.lastValues[inputKey]
if !ok {
lv = &lastValueState{}
sv.lastValues[inputKey] = lv
}
if ok || keepFirstSample {
if s.value >= lv.value {
sv.total += s.value - lv.value
@ -101,6 +97,7 @@ func (as *totalAggrState) pushSamples(samples []pushSample) {
}
lv.value = s.value
lv.deleteDeadline = deleteDeadline
sv.lastValues[inputKey] = lv
sv.deleteDeadline = deleteDeadline
}
sv.mu.Unlock()