From fc330642e497a5bdcb3dc3ab982a81b4e67c904c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 26 Dec 2025 23:54:17 +0530 Subject: [PATCH] promql: Preallocate slice in extendFloats Signed-off-by: Rushabh Mehta --- promql/engine.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index a9f0dd2952..112fe17426 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -4418,9 +4418,9 @@ func extendFloats(floats []FPoint, mint, maxt int64, smoothed bool) []FPoint { lastSampleIndex-- } - // TODO: Preallocate the length of the new list. - out := make([]FPoint, 0) - // Create the new floats list with the boundary samples and the inner samples. + count := max(lastSampleIndex-firstSampleIndex+1, 0) + out := make([]FPoint, 0, count+2) + out = append(out, FPoint{T: mint, F: left}) out = append(out, floats[firstSampleIndex:lastSampleIndex+1]...) out = append(out, FPoint{T: maxt, F: right})