From d57280efb2d387d50b80b40c7d585ea282eba8c4 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Thu, 19 Oct 2017 22:12:18 +0200 Subject: [PATCH] Use GetByKey() in typeLister_NonNamespacedGet The Get() function of non-namespace lister passes a temporary object to indexer.Get() in order to fetch the actual object from the indexer. This may cause Go to allocate the temporary object on the heap instead of the stack, as it is passed into interfaces. For non-namespaced objects, Get(&Type{ObjectMeta: v1.ObjectMeta{Name: name}}) should be equivalent to GetByKey(name). This could be the root cause of excessive allocations, e.g. in tests clusterRoleLister.Get() has trigger 4 billion allocations. See https://github.com/openshift/origin/issues/16954 Signed-off-by: Christian Heimes --- .../k8s.io/code-generator/cmd/lister-gen/generators/lister.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go b/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go index 9466e3cb07d..e25a5a1a189 100644 --- a/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go +++ b/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go @@ -322,8 +322,7 @@ func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|pu var typeLister_NonNamespacedGet = ` // Get retrieves the $.type|public$ from the index for a given name. func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) { - key := &$.type|raw${ObjectMeta: $.objectMeta|raw${Name: name}} - obj, exists, err := s.indexer.Get(key) + obj, exists, err := s.indexer.GetByKey(name) if err != nil { return nil, err }