Commit d57280ef authored by Christian Heimes's avatar Christian Heimes

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/16954Signed-off-by: 's avatarChristian Heimes <cheimes@redhat.com>
parent c3d47b68
......@@ -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
}
......
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