enhancement: replace sort.Slice with slices.SortFunc to reduce reflection

This commit is contained in:
justin
2022-04-18 10:35:43 +08:00
parent c6ec5269f4
commit 3551ca2fcf
25 changed files with 117 additions and 139 deletions

View File

@@ -4,12 +4,11 @@ import (
"flag"
"fmt"
"github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/storage/types"
"io"
"sort"
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/chrislusf/seaweedfs/weed/storage/types"
"golang.org/x/exp/slices"
"io"
)
func init() {
@@ -411,8 +410,8 @@ func doBalanceEcRack(commandEnv *CommandEnv, ecRack *EcRack, applyBalancing bool
hasMove := true
for hasMove {
hasMove = false
sort.Slice(rackEcNodes, func(i, j int) bool {
return rackEcNodes[i].freeEcSlot > rackEcNodes[j].freeEcSlot
slices.SortFunc(rackEcNodes, func(a, b *EcNode) bool {
return a.freeEcSlot > b.freeEcSlot
})
emptyNode, fullNode := rackEcNodes[0], rackEcNodes[len(rackEcNodes)-1]
emptyNodeShardCount, fullNodeShardCount := ecNodeIdToShardCount[emptyNode.info.Id], ecNodeIdToShardCount[fullNode.info.Id]
@@ -492,8 +491,8 @@ func pickNEcShardsToMoveFrom(ecNodes []*EcNode, vid needle.VolumeId, n int) map[
})
}
}
sort.Slice(candidateEcNodes, func(i, j int) bool {
return candidateEcNodes[i].shardCount > candidateEcNodes[j].shardCount
slices.SortFunc(candidateEcNodes, func(a, b *CandidateEcNode) bool {
return a.shardCount > b.shardCount
})
for i := 0; i < n; i++ {
selectedEcNodeIndex := -1