Merge pull request #72406 from wojtek-t/speedup_listers

Speedup listers for empty selectors

Kubernetes-commit: 7c112762b0df87f3a1772f3bbede7fe9185fa249
This commit is contained in:
Kubernetes Publisher 2018-12-28 08:17:06 -08:00
commit 8145e5e321
2 changed files with 71 additions and 51 deletions

102
Godeps/Godeps.json generated
View File

@ -408,207 +408,207 @@
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/equality", "ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/errors", "ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/meta", "ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/resource", "ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion", "ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams", "ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/fields", "ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/labels", "ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime", "ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema", "ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/selection", "ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/types", "ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/cache", "ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/clock", "ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/diff", "ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/errors", "ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/framer", "ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr", "ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/json", "ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch", "ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/naming", "ImportPath": "k8s.io/apimachinery/pkg/util/naming",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/net", "ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand", "ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime", "ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/sets", "ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch", "ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation", "ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field", "ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/wait", "ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml", "ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/version", "ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/watch", "ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "98853ca904e81a25e2000cae7f077dc30f81b85f" "Rev": "9c4c366543346abeca2a5cd2c40cf1a30d19a2ec"
}, },
{ {
"ImportPath": "k8s.io/klog", "ImportPath": "k8s.io/klog",

View File

@ -31,7 +31,14 @@ import (
type AppendFunc func(interface{}) type AppendFunc func(interface{})
func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error { func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error {
selectAll := selector.Empty()
for _, m := range store.List() { for _, m := range store.List() {
if selectAll {
// Avoid computing labels of the objects to speed up common flows
// of listing all objects.
appendFn(m)
continue
}
metadata, err := meta.Accessor(m) metadata, err := meta.Accessor(m)
if err != nil { if err != nil {
return err return err
@ -44,8 +51,15 @@ func ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error {
} }
func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selector, appendFn AppendFunc) error { func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selector, appendFn AppendFunc) error {
selectAll := selector.Empty()
if namespace == metav1.NamespaceAll { if namespace == metav1.NamespaceAll {
for _, m := range indexer.List() { for _, m := range indexer.List() {
if selectAll {
// Avoid computing labels of the objects to speed up common flows
// of listing all objects.
appendFn(m)
continue
}
metadata, err := meta.Accessor(m) metadata, err := meta.Accessor(m)
if err != nil { if err != nil {
return err return err
@ -74,6 +88,12 @@ func ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selec
return nil return nil
} }
for _, m := range items { for _, m := range items {
if selectAll {
// Avoid computing labels of the objects to speed up common flows
// of listing all objects.
appendFn(m)
continue
}
metadata, err := meta.Accessor(m) metadata, err := meta.Accessor(m)
if err != nil { if err != nil {
return err return err