Skip to content

Commit

Permalink
Merge pull request #4171 from justinsb/cache_orgid
Browse files Browse the repository at this point in the history
Cache the OrgId for nameReferenceTransformer
  • Loading branch information
k8s-ci-robot committed Sep 7, 2021
2 parents 4d002af + 6552b90 commit d4e3b4f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/internal/accumulator/namereferencetransformer.go
Expand Up @@ -11,6 +11,7 @@ import (
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/kyaml/resid"
)

type nameReferenceTransformer struct {
Expand Down Expand Up @@ -109,11 +110,18 @@ func debug(fMap filterMap) {
// 'spec/scaleTargetRef/name' field. Return a filter that can do that.
func (t *nameReferenceTransformer) determineFilters(
resources []*resource.Resource) (fMap filterMap) {

// We cache the resource OrgId values because they don't change and otherwise are very visible in a memory pprof
resourceOrgIds := make([]resid.ResId, len(resources))
for i, resource := range resources {
resourceOrgIds[i] = resource.OrgId()
}

fMap = make(filterMap)
for _, backReference := range t.backRefs {
for _, referrerSpec := range backReference.Referrers {
for _, res := range resources {
if res.OrgId().IsSelected(&referrerSpec.Gvk) {
for i, res := range resources {
if resourceOrgIds[i].IsSelected(&referrerSpec.Gvk) {
// If this is true, the res might be a referrer, and if
// so, the name reference it holds might need an update.
if resHasField(res, referrerSpec.Path) {
Expand Down

0 comments on commit d4e3b4f

Please sign in to comment.