Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2024-03-01 08:24:11 +01:00
parent 0824e6e4ca
commit df1e8f7bc0
2 changed files with 42 additions and 13 deletions

View file

@ -1016,6 +1016,7 @@ type evaluator struct {
lookbackDelta time.Duration lookbackDelta time.Duration
samplesStats *stats.QuerySamples samplesStats *stats.QuerySamples
noStepSubqueryIntervalFn func(rangeMillis int64) int64 noStepSubqueryIntervalFn func(rangeMillis int64) int64
reuseHistograms bool
} }
// errorf causes a panic with the input formatted into an error. // errorf causes a panic with the input formatted into an error.
@ -2152,10 +2153,19 @@ loop:
histograms = getMatrixSelectorHPoints() histograms = getMatrixSelectorHPoints()
} }
n := len(histograms) n := len(histograms)
if n < cap(histograms) { if ev.reuseHistograms {
histograms = histograms[:n+1] if n < cap(histograms) {
histograms = histograms[:n+1]
} else {
histograms = append(histograms, HPoint{H: &histogram.FloatHistogram{}})
}
} else { } else {
histograms = append(histograms, HPoint{H: &histogram.FloatHistogram{}}) if n < cap(histograms) {
histograms = histograms[:n+1]
histograms[n].H = nil
} else {
histograms = append(histograms, HPoint{})
}
} }
histograms[n].T, histograms[n].H = buf.AtFloatHistogram(histograms[n].H) histograms[n].T, histograms[n].H = buf.AtFloatHistogram(histograms[n].H)
if value.IsStaleNaN(histograms[n].H.Sum) { if value.IsStaleNaN(histograms[n].H.Sum) {
@ -2195,10 +2205,19 @@ loop:
histograms = getMatrixSelectorHPoints() histograms = getMatrixSelectorHPoints()
} }
n := len(histograms) n := len(histograms)
if n < cap(histograms) { if ev.reuseHistograms {
histograms = histograms[:n+1] if n < cap(histograms) {
histograms = histograms[:n+1]
} else {
histograms = append(histograms, HPoint{H: &histogram.FloatHistogram{}})
}
} else { } else {
histograms = append(histograms, HPoint{H: &histogram.FloatHistogram{}}) if n < cap(histograms) {
histograms = histograms[:n+1]
histograms[n].H = nil
} else {
histograms = append(histograms, HPoint{})
}
} }
histograms[n].T, histograms[n].H = it.AtFloatHistogram(histograms[n].H) histograms[n].T, histograms[n].H = it.AtFloatHistogram(histograms[n].H)
if value.IsStaleNaN(histograms[n].H.Sum) { if value.IsStaleNaN(histograms[n].H.Sum) {

View file

@ -240,6 +240,8 @@ func (s fhSample) Type() chunkenc.ValueType {
type sampleRing struct { type sampleRing struct {
delta int64 delta int64
reuseHistograms bool
// Lookback buffers. We use iBuf for mixed samples, but one of the three // Lookback buffers. We use iBuf for mixed samples, but one of the three
// concrete ones for homogenous samples. (Only one of the four bufs is // concrete ones for homogenous samples. (Only one of the four bufs is
// allowed to be populated!) This avoids the overhead of the interface // allowed to be populated!) This avoids the overhead of the interface
@ -385,7 +387,7 @@ func (it *SampleRingIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (in
it.fh.CopyTo(fh) it.fh.CopyTo(fh)
return it.t, fh return it.t, fh
} }
return it.t, it.fh.Copy() return it.t, it.fh
} }
func (it *SampleRingIterator) AtT() int64 { func (it *SampleRingIterator) AtT() int64 {
@ -680,10 +682,14 @@ func addH(s hSample, buf []hSample, r *sampleRing) []hSample {
} }
buf[r.i].t = s.t buf[r.i].t = s.t
if buf[r.i].h == nil { if r.reuseHistograms {
buf[r.i].h = s.h.Copy() if buf[r.i].h == nil {
buf[r.i].h = s.h.Copy()
} else {
s.h.CopyTo(buf[r.i].h)
}
} else { } else {
s.h.CopyTo(buf[r.i].h) buf[r.i].h = s.h
} }
r.l++ r.l++
@ -724,10 +730,14 @@ func addFH(s fhSample, buf []fhSample, r *sampleRing) []fhSample {
} }
buf[r.i].t = s.t buf[r.i].t = s.t
if buf[r.i].fh == nil { if r.reuseHistograms {
buf[r.i].fh = s.fh.Copy() if buf[r.i].fh == nil {
buf[r.i].fh = s.fh.Copy()
} else {
s.fh.CopyTo(buf[r.i].fh)
}
} else { } else {
s.fh.CopyTo(buf[r.i].fh) buf[r.i].fh = s.fh
} }
r.l++ r.l++