Commit 94666b4a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #31112 from wojtek-t/set_unsorted_list

Automatic merge from submit-queue Avoid sorting lists when unnecessary I've seen ThreadSafeMap::List consuming ~30% of whole CPU usage, spending the whole time in sorting (while it is in fact completely unneded).
parents c958d3d4 28040559
...@@ -337,6 +337,15 @@ func (s $.type|public$) List() []$.type|raw$ { ...@@ -337,6 +337,15 @@ func (s $.type|public$) List() []$.type|raw$ {
return []$.type|raw$(res) return []$.type|raw$(res)
} }
// UnsortedList returns the slice with contents in random order.
func (s $.type|public$) UnsortedList() []$.type|raw$ {
res :=make([]$.type|raw$, 0, len(s))
for key := range s {
res = append(res, key)
}
return res
}
// Returns a single element from the set. // Returns a single element from the set.
func (s $.type|public$) PopAny() ($.type|raw$, bool) { func (s $.type|public$) PopAny() ($.type|raw$, bool) {
for key := range s { for key := range s {
......
...@@ -151,7 +151,7 @@ func (c *threadSafeMap) Index(indexName string, obj interface{}) ([]interface{}, ...@@ -151,7 +151,7 @@ func (c *threadSafeMap) Index(indexName string, obj interface{}) ([]interface{},
returnKeySet := sets.String{} returnKeySet := sets.String{}
for _, indexKey := range indexKeys { for _, indexKey := range indexKeys {
set := index[indexKey] set := index[indexKey]
for _, key := range set.List() { for _, key := range set.UnsortedList() {
returnKeySet.Insert(key) returnKeySet.Insert(key)
} }
} }
......
...@@ -174,6 +174,15 @@ func (s Byte) List() []byte { ...@@ -174,6 +174,15 @@ func (s Byte) List() []byte {
return []byte(res) return []byte(res)
} }
// UnsortedList returns the slice with contents in random order.
func (s Byte) UnsortedList() []byte {
res := make([]byte, 0, len(s))
for key := range s {
res = append(res, key)
}
return res
}
// Returns a single element from the set. // Returns a single element from the set.
func (s Byte) PopAny() (byte, bool) { func (s Byte) PopAny() (byte, bool) {
for key := range s { for key := range s {
......
...@@ -174,6 +174,15 @@ func (s Int) List() []int { ...@@ -174,6 +174,15 @@ func (s Int) List() []int {
return []int(res) return []int(res)
} }
// UnsortedList returns the slice with contents in random order.
func (s Int) UnsortedList() []int {
res := make([]int, 0, len(s))
for key := range s {
res = append(res, key)
}
return res
}
// Returns a single element from the set. // Returns a single element from the set.
func (s Int) PopAny() (int, bool) { func (s Int) PopAny() (int, bool) {
for key := range s { for key := range s {
......
...@@ -174,6 +174,15 @@ func (s Int64) List() []int64 { ...@@ -174,6 +174,15 @@ func (s Int64) List() []int64 {
return []int64(res) return []int64(res)
} }
// UnsortedList returns the slice with contents in random order.
func (s Int64) UnsortedList() []int64 {
res := make([]int64, 0, len(s))
for key := range s {
res = append(res, key)
}
return res
}
// Returns a single element from the set. // Returns a single element from the set.
func (s Int64) PopAny() (int64, bool) { func (s Int64) PopAny() (int64, bool) {
for key := range s { for key := range s {
......
...@@ -174,6 +174,15 @@ func (s String) List() []string { ...@@ -174,6 +174,15 @@ func (s String) List() []string {
return []string(res) return []string(res)
} }
// UnsortedList returns the slice with contents in random order.
func (s String) UnsortedList() []string {
res := make([]string, 0, len(s))
for key := range s {
res = append(res, key)
}
return res
}
// Returns a single element from the set. // Returns a single element from the set.
func (s String) PopAny() (string, bool) { func (s String) PopAny() (string, bool) {
for key := range s { for key := range s {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment