mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
perf: optimize RNode GetAnnotations and GetLabels
This commit optimizes in three ways: 1. For heavily used functions, allocate memory to avoid overhead associated with map and array re-sizing. 2. Where appropriate, limit annotation and label retrievals to only the desired keys. 3. Adjust annotation and label retrieval to avoid unnecessary temporary object creation.
This commit is contained in:
@@ -35,7 +35,10 @@ func PrevIds(n *yaml.RNode) ([]resid.ResId, error) {
|
||||
var ids []resid.ResId
|
||||
// TODO: merge previous names and namespaces into one list of
|
||||
// pairs on one annotation so there is no chance of error
|
||||
annotations := n.GetAnnotations()
|
||||
annotations := n.GetAnnotations(
|
||||
BuildAnnotationPreviousNames,
|
||||
BuildAnnotationPreviousNamespaces,
|
||||
BuildAnnotationPreviousKinds)
|
||||
if _, ok := annotations[BuildAnnotationPreviousNames]; !ok {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -51,6 +54,7 @@ func PrevIds(n *yaml.RNode) ([]resid.ResId, error) {
|
||||
}
|
||||
apiVersion := n.GetApiVersion()
|
||||
group, version := resid.ParseGroupVersion(apiVersion)
|
||||
ids = make([]resid.ResId, 0, len(names))
|
||||
for i := range names {
|
||||
gvk := resid.Gvk{
|
||||
Group: group,
|
||||
|
||||
Reference in New Issue
Block a user