[#236] netmap: Reduce allocations in getSelection()
``` goos: linux goarch: amd64 pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz │ new │ alloc │ │ sec/op │ sec/op vs base │ Netmap_ContainerNodes/REP_2-8 9.227µ ± 13% 8.677µ ± 6% ~ (p=0.165 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 9.189µ ± 7% 7.946µ ± 14% -13.53% (p=0.001 n=10) geomean 9.208µ 8.303µ -9.82% │ new │ alloc │ │ B/op │ B/op vs base │ Netmap_ContainerNodes/REP_2-8 8.320Ki ± 0% 7.734Ki ± 0% -7.04% (p=0.000 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 7.742Ki ± 0% 7.156Ki ± 0% -7.57% (p=0.000 n=10) geomean 8.026Ki 7.440Ki -7.31% │ new │ alloc │ │ allocs/op │ allocs/op vs base │ Netmap_ContainerNodes/REP_2-8 122.00 ± 0% 92.00 ± 0% -24.59% (p=0.000 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 122.00 ± 0% 92.00 ± 0% -24.59% (p=0.000 n=10) geomean 122.0 92.00 -24.59% ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
a69f00903c
commit
159a50fcf0
2 changed files with 8 additions and 7 deletions
|
@ -72,12 +72,6 @@ func newMinAgg() aggregator {
|
||||||
return new(minAgg)
|
return new(minAgg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMeanIQRAgg returns an aggregator which
|
|
||||||
// computes mean value of values from IQR interval.
|
|
||||||
func newMeanIQRAgg() aggregator {
|
|
||||||
return new(meanIQRAgg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// newReverseMinNorm returns a normalizer which
|
// newReverseMinNorm returns a normalizer which
|
||||||
// normalize values in range of 0.0 to 1.0 to a minimum value.
|
// normalize values in range of 0.0 to 1.0 to a minimum value.
|
||||||
func newReverseMinNorm(min float64) normalizer {
|
func newReverseMinNorm(min float64) normalizer {
|
||||||
|
@ -116,6 +110,11 @@ func (a *minAgg) Compute() float64 {
|
||||||
return a.min
|
return a.min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *meanIQRAgg) clear() {
|
||||||
|
a.k = 0
|
||||||
|
a.arr = a.arr[:0]
|
||||||
|
}
|
||||||
|
|
||||||
func (a *meanIQRAgg) Add(n float64) {
|
func (a *meanIQRAgg) Add(n float64) {
|
||||||
a.arr = append(a.arr, n)
|
a.arr = append(a.arr, n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,10 @@ func (c *context) getSelection(s netmap.Selector) ([]nodes, error) {
|
||||||
|
|
||||||
if len(c.hrwSeed) != 0 {
|
if len(c.hrwSeed) != 0 {
|
||||||
weights := make([]float64, len(res))
|
weights := make([]float64, len(res))
|
||||||
|
a := new(meanIQRAgg)
|
||||||
for i := range res {
|
for i := range res {
|
||||||
weights[i] = calcBucketWeight(res[i], newMeanIQRAgg(), c.weightFunc)
|
a.clear()
|
||||||
|
weights[i] = calcBucketWeight(res[i], a, c.weightFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
hrw.SortHasherSliceByWeightValue(res, weights, c.hrwSeedHash)
|
hrw.SortHasherSliceByWeightValue(res, weights, c.hrwSeedHash)
|
||||||
|
|
Loading…
Reference in a new issue