Merge pull request #17743 from RushabhMehta2005/optimization/extend-floats-prealloc

promql: preallocate slice in extendFloats optimization
This commit is contained in:
Julien 2026-01-09 12:40:00 +01:00 committed by GitHub
commit f0eaf596fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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})