oxy icon indicating copy to clipboard operation
oxy copied to clipboard

memmetrics: Optimize RollingCounter Inc and Count operations

Open AlexisMontagne opened this issue 7 years ago • 0 comments

The overall performance of the counter has been improved, there is a little performance regression in a corner case (large bucket with contiguous values)

Find attached some benchmark results of this modification:

benchmark                                      old ns/op     new ns/op     delta
BenchmarkCounterIncOnly/size-3-4               203           53.4          -73.69%
BenchmarkCounterIncOnly/size-5-4               192           52.3          -72.76%
BenchmarkCounterIncOnly/size-10-4              198           59.0          -70.20%
BenchmarkCounterIncOnly/size-20-4              199           62.4          -68.64%
BenchmarkCounterIncOnly/size-50-4              196           58.5          -70.15%
BenchmarkCounterIncOnly/size-100-4             189           57.5          -69.58%
BenchmarkCounterIncCountContigu/size-3-4       249           111           -55.42%
BenchmarkCounterIncCountContigu/size-5-4       249           125           -49.80%
BenchmarkCounterIncCountContigu/size-10-4      262           180           -31.30%
BenchmarkCounterIncCountContigu/size-20-4      257           285           +10.89%
BenchmarkCounterIncCountContigu/size-50-4      270           610           +125.93%
BenchmarkCounterIncCountContigu/size-100-4     295           1054          +257.29%
BenchmarkCounterIncCountSparse/size-3-4        379           104           -72.56%
BenchmarkCounterIncCountSparse/size-5-4        485           95.9          -80.23%
BenchmarkCounterIncCountSparse/size-10-4       482           102           -78.84%
BenchmarkCounterIncCountSparse/size-20-4       478           168           -64.85%
BenchmarkCounterIncCountSparse/size-50-4       488           181           -62.91%
BenchmarkCounterIncCountSparse/size-100-4      494           298           -39.68%

FYI: The struct is now really thread safe.

AlexisMontagne avatar Nov 21 '18 23:11 AlexisMontagne