fix: [fs] CompleteMultipart use trie structure for partMatch (#10522)

performance improves by around 100x or more

```
go test -v -run NONE -bench BenchmarkGetPartFile
goos: linux
goarch: amd64
pkg: github.com/minio/minio/cmd
BenchmarkGetPartFileWithTrie
BenchmarkGetPartFileWithTrie-4          1000000000               0.140 ns/op           0 B/op          0 allocs/op
PASS
ok      github.com/minio/minio/cmd      1.737s
```

fixes #10520
This commit is contained in:
Harshavardhana
2020-09-21 01:18:13 -07:00
committed by GitHub
parent 230fc0d186
commit 3831cc9e3b
5 changed files with 52 additions and 60 deletions

View File

@@ -21,7 +21,7 @@ package trie
// Node trie tree node container carries value and children.
type Node struct {
exists bool
value interface{}
value string
child map[rune]*Node // runes as child.
}
@@ -29,7 +29,7 @@ type Node struct {
func newNode() *Node {
return &Node{
exists: false,
value: nil,
value: "",
child: make(map[rune]*Node),
}
}
@@ -65,16 +65,16 @@ func (t *Trie) Insert(key string) {
}
// PrefixMatch - prefix match.
func (t *Trie) PrefixMatch(key string) []interface{} {
func (t *Trie) PrefixMatch(key string) []string {
node, _ := t.findNode(key)
if node != nil {
return t.Walk(node)
if node == nil {
return nil
}
return []interface{}{}
return t.Walk(node)
}
// Walk the tree.
func (t *Trie) Walk(node *Node) (ret []interface{}) {
func (t *Trie) Walk(node *Node) (ret []string) {
if node.exists {
ret = append(ret, node.value)
}