Skip to content

Commit 0b7ce15

Browse files
tiranmfojtik
authored andcommitted
UPSTREAM: 54257: 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 openshift/origin#16954 Signed-off-by: Christian Heimes <[email protected]>
1 parent 339287f commit 0b7ce15

File tree

1 file changed

+1
-2
lines changed
  • staging/src/k8s.io/code-generator/cmd/lister-gen/generators

1 file changed

+1
-2
lines changed

staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|pu
323323
var typeLister_NonNamespacedGet = `
324324
// Get retrieves the $.type|public$ from the index for a given name.
325325
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
326-
key := &$.type|raw${ObjectMeta: $.objectMeta|raw${Name: name}}
327-
obj, exists, err := s.indexer.Get(key)
326+
obj, exists, err := s.indexer.GetByKey(name)
328327
if err != nil {
329328
return nil, err
330329
}

0 commit comments

Comments
 (0)