From 5fd3a6a7b54a4e97ede1fa56f77aa49996016c95 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 17 Jan 2025 15:51:22 +0800 Subject: [PATCH] optimize float series memory allocation --- pkg/types/series_float64.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/types/series_float64.go b/pkg/types/series_float64.go index 904d229580..3e06b5e59d 100644 --- a/pkg/types/series_float64.go +++ b/pkg/types/series_float64.go @@ -12,7 +12,13 @@ type Float64Series struct { func NewFloat64Series(v ...float64) *Float64Series { s := &Float64Series{} - s.Slice = v + + if len(v) == 0 { + s.Slice = make([]float64, 0, 1024) + } else { + s.Slice = v + } + s.SeriesBase.Series = &s.Slice return s } @@ -60,7 +66,6 @@ func (f *Float64Series) AddSubscriber(fn func(v float64)) { } } - // Bind binds the source event to the target (Float64Calculator) // A Float64Calculator should be able to calculate the float64 result from a single float64 argument input func (f *Float64Series) Bind(source Float64Source, target Float64Calculator) {