Move bucket index calculations to the place where they are used

This can help https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096
This commit is contained in:
Aliaksandr Valialkin 2021-02-28 17:39:11 +02:00
parent 5523b934ae
commit 16e4558792

View File

@ -86,6 +86,13 @@ func (h *Histogram) Update(v float64) {
return return
} }
bucketIdx := (math.Log10(v) - e10Min) * bucketsPerDecimal bucketIdx := (math.Log10(v) - e10Min) * bucketsPerDecimal
h.mu.Lock()
h.sum += v
if bucketIdx < 0 {
h.lower++
} else if bucketIdx >= bucketsCount {
h.upper++
} else {
idx := uint(bucketIdx) idx := uint(bucketIdx)
if bucketIdx == float64(idx) { if bucketIdx == float64(idx) {
// Edge case for 10^n values, which must go to the lower bucket // Edge case for 10^n values, which must go to the lower bucket
@ -94,13 +101,6 @@ func (h *Histogram) Update(v float64) {
} }
decimalBucketIdx := idx / bucketsPerDecimal decimalBucketIdx := idx / bucketsPerDecimal
offset := idx % bucketsPerDecimal offset := idx % bucketsPerDecimal
h.mu.Lock()
h.sum += v
if bucketIdx < 0 {
h.lower++
} else if bucketIdx >= bucketsCount {
h.upper++
} else {
db := h.decimalBuckets[decimalBucketIdx] db := h.decimalBuckets[decimalBucketIdx]
if db == nil { if db == nil {
var b [bucketsPerDecimal]uint64 var b [bucketsPerDecimal]uint64