You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
improve defaultSize adjustment for rare case when next few j > 0 p.calls after sort (==> a) have a[j].calls ~= a[0].calls and some of them a[j].size > defaultSize (== a[0].size) + added test TestPoolCalibrateWithAdjustment
+ also replaced floating-point arithmetic with integer muldiv equivalent
+ fix tests fn allocNBytes()
+ some microoptimizations
maxPercentileNumer=maxPercentileRNumer/maxPercentileGcd// simplified numerator of maxPercentile
27
+
maxPercentileDenom=fractionDenominator/maxPercentileGcd// simplified denominator of maxPercentile
28
+
29
+
// allowable size spread for DefaultSize additional adjustment
30
+
calibrateDefaultSizeAdjustmentsSpread=0.05// down to 5% of initial DefaultSize` calls count
31
+
calibrateDefaultSizeAdjustmentsFactor=1-calibrateDefaultSizeAdjustmentsSpread// see calibrate() below
32
+
33
+
// regular fraction of calibrateDefaultSizeAdjustmentsFactor
34
+
calibrateDefaultSizeAdjustmentsFactorRNumer=uint64(calibrateDefaultSizeAdjustmentsFactor*float64(fractionDenominator)) // numerator of calibrateDefaultSizeAdjustmentsFactor
calibrateDefaultSizeAdjustmentsFactorNumer=calibrateDefaultSizeAdjustmentsFactorRNumer/calibrateDSASGcd// simplified numerator of calibrateDefaultSizeAdjustmentsFactor
37
+
calibrateDefaultSizeAdjustmentsFactorDenom=fractionDenominator/calibrateDSASGcd// simplified denominator of calibrateDefaultSizeAdjustmentsFactor
18
38
)
19
39
20
40
// Pool represents byte buffer pool.
@@ -84,7 +104,9 @@ func (p *Pool) calibrate() {
84
104
}
85
105
86
106
a:=make(callSizes, 0, steps)
87
-
varcallsSumuint64
107
+
108
+
callsSum:=uint64(0)
109
+
88
110
fori:=uint64(0); i<steps; i++ {
89
111
calls:=atomic.SwapUint64(&p.calls[i], 0)
90
112
callsSum+=calls
@@ -98,17 +120,43 @@ func (p *Pool) calibrate() {
98
120
defaultSize:=a[0].size
99
121
maxSize:=defaultSize
100
122
101
-
maxSum:=uint64(float64(callsSum) *maxPercentile)
102
-
callsSum=0
103
-
fori:=0; i<steps; i++ {
123
+
// callsSum <= steps * calibrateCallsThreshold + maybe small R = callsSumMaxValue + R <<<< (MaxUint64 / fractionDenominator),
124
+
// maxPercentileNumer < fractionDenominator, therefore, integer multiplication by a fraction can be used without overflow
0 commit comments