forked from TrueCloudLab/frostfs-sdk-go
[#236] netmap: Reuse slice for weights in ContainerNodes()
``` goos: linux goarch: amd64 pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz │ alloc │ weights │ │ sec/op │ sec/op vs base │ Netmap_ContainerNodes/REP_2-8 8.677µ ± 6% 8.384µ ± 10% ~ (p=0.247 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 7.946µ ± 14% 7.998µ ± 6% ~ (p=0.481 n=10) geomean 8.303µ 8.189µ -1.38% │ alloc │ weights │ │ B/op │ B/op vs base │ Netmap_ContainerNodes/REP_2-8 7.734Ki ± 0% 7.617Ki ± 0% -1.52% (p=0.000 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 7.156Ki ± 0% 7.039Ki ± 0% -1.64% (p=0.000 n=10) geomean 7.440Ki 7.322Ki -1.58% │ alloc │ weights │ │ allocs/op │ allocs/op vs base │ Netmap_ContainerNodes/REP_2-8 92.00 ± 0% 77.00 ± 0% -16.30% (p=0.000 n=10) Netmap_ContainerNodes/REP_2_IN_X_CBF_2_SELECT_2_FROM_*_AS_X-8 92.00 ± 0% 77.00 ± 0% -16.30% (p=0.000 n=10) geomean 92.00 77.00 -16.30% ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
159a50fcf0
commit
6729f54c4e
2 changed files with 11 additions and 5 deletions
|
@ -113,9 +113,10 @@ func (n nodes) Hash() uint64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// weights returns slice of nodes weights W.
|
func (n nodes) appendWeightsTo(wf weightFunc, w []float64) []float64 {
|
||||||
func (n nodes) weights(wf weightFunc) []float64 {
|
if cap(w) < len(n) {
|
||||||
w := make([]float64, 0, len(n))
|
w = make([]float64, 0, len(n))
|
||||||
|
}
|
||||||
for i := range n {
|
for i := range n {
|
||||||
w = append(w, wf(n[i]))
|
w = append(w, wf(n[i]))
|
||||||
}
|
}
|
||||||
|
@ -149,10 +150,13 @@ func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeIn
|
||||||
wf := defaultWeightFunc(m.nodes)
|
wf := defaultWeightFunc(m.nodes)
|
||||||
result := make([][]NodeInfo, len(vectors))
|
result := make([][]NodeInfo, len(vectors))
|
||||||
|
|
||||||
|
var ws []float64
|
||||||
|
|
||||||
for i := range vectors {
|
for i := range vectors {
|
||||||
result[i] = make([]NodeInfo, len(vectors[i]))
|
result[i] = make([]NodeInfo, len(vectors[i]))
|
||||||
copy(result[i], vectors[i])
|
copy(result[i], vectors[i])
|
||||||
hrw.SortHasherSliceByWeightValue(result[i], nodes(result[i]).weights(wf), h)
|
ws = nodes(result[i]).appendWeightsTo(wf, ws[:0])
|
||||||
|
hrw.SortHasherSliceByWeightValue(result[i], ws, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
@ -171,8 +171,10 @@ func (c *context) getSelectionBase(s netmap.Selector) []nodeAttrPair {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.hrwSeed) != 0 {
|
if len(c.hrwSeed) != 0 {
|
||||||
|
var ws []float64
|
||||||
for i := range result {
|
for i := range result {
|
||||||
hrw.SortHasherSliceByWeightValue(result[i].nodes, result[i].nodes.weights(c.weightFunc), c.hrwSeedHash)
|
ws = result[i].nodes.appendWeightsTo(c.weightFunc, ws[:0])
|
||||||
|
hrw.SortHasherSliceByWeightValue(result[i].nodes, ws, c.hrwSeedHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue