mirror of
https://github.com/minio/minio.git
synced 2025-12-07 00:02:31 -05:00
reduce CPU usage upto 50% in readdir (#10466)
This commit is contained in:
@@ -29,29 +29,20 @@ type TreeWalkResult struct {
|
||||
}
|
||||
|
||||
// Return entries that have prefix prefixEntry.
|
||||
// Note: input entries are expected to be sorted.
|
||||
// The supplied entries are modified and the returned string is a subslice of entries.
|
||||
func filterMatchingPrefix(entries []string, prefixEntry string) []string {
|
||||
start := 0
|
||||
end := len(entries)
|
||||
for {
|
||||
if start == end {
|
||||
break
|
||||
}
|
||||
if HasPrefix(entries[start], prefixEntry) {
|
||||
break
|
||||
}
|
||||
start++
|
||||
if len(entries) == 0 || prefixEntry == "" {
|
||||
return entries
|
||||
}
|
||||
for {
|
||||
if start == end {
|
||||
break
|
||||
// Write to the beginning of entries.
|
||||
dst := entries[:0]
|
||||
for _, s := range entries {
|
||||
if !HasPrefix(s, prefixEntry) {
|
||||
continue
|
||||
}
|
||||
if HasPrefix(entries[end-1], prefixEntry) {
|
||||
break
|
||||
}
|
||||
end--
|
||||
dst = append(dst, s)
|
||||
}
|
||||
return entries[start:end]
|
||||
return dst
|
||||
}
|
||||
|
||||
// xl.ListDir returns entries with trailing "/" for directories. At the object layer
|
||||
@@ -101,12 +92,12 @@ type IsLeafFunc func(string, string) bool
|
||||
type IsLeafDirFunc func(string, string) bool
|
||||
|
||||
func filterListEntries(bucket, prefixDir string, entries []string, prefixEntry string, isLeaf IsLeafFunc) ([]string, bool) {
|
||||
// Listing needs to be sorted.
|
||||
sort.Strings(entries)
|
||||
|
||||
// Filter entries that have the prefix prefixEntry.
|
||||
entries = filterMatchingPrefix(entries, prefixEntry)
|
||||
|
||||
// Listing needs to be sorted.
|
||||
sort.Strings(entries)
|
||||
|
||||
// Can isLeaf() check be delayed till when it has to be sent down the
|
||||
// TreeWalkResult channel?
|
||||
delayIsLeaf := delayIsLeafCheck(entries)
|
||||
@@ -124,6 +115,7 @@ func filterListEntries(bucket, prefixDir string, entries []string, prefixEntry s
|
||||
// Sort again after removing trailing "/" for objects as the previous sort
|
||||
// does not hold good anymore.
|
||||
sort.Strings(entries)
|
||||
|
||||
return entries, false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user