From d5bfb706b384eeab0f072516754a0d087e326cb1 Mon Sep 17 00:00:00 2001 From: antyagi Date: Wed, 18 Feb 2026 15:04:47 +0530 Subject: [PATCH 1/7] feat: helm performance improvement by deep copying coalesce globals Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index 5994febbc..d8f10a7e8 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -19,7 +19,6 @@ package util import ( "fmt" "log" - "maps" "helm.sh/helm/v4/internal/copystructure" chart "helm.sh/helm/v4/pkg/chart" @@ -160,7 +159,8 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ // tables in globals. for key, val := range sg { if istable(val) { - vv := copyMap(val.(map[string]any)) + valCopy, _ := copystructure.Copy(val) + vv := valCopy.(map[string]interface{}) if destv, ok := dg[key]; !ok { // Here there is no merge. We're just adding. dg[key] = vv @@ -189,11 +189,6 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ dest[common.GlobalKey] = dg } -func copyMap(src map[string]any) map[string]any { - m := make(map[string]any, len(src)) - maps.Copy(m, src) - return m -} // coalesceValues builds up a values map for a particular chart. // From 05ab8137453b1c2ed6892f3291da8e871edb168f Mon Sep 17 00:00:00 2001 From: antyagi Date: Sat, 7 Mar 2026 01:15:27 +0530 Subject: [PATCH 2/7] feat: handling error in coalesce Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index d8f10a7e8..8bafcd18e 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -121,7 +121,10 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi dvmap := dv.(map[string]any) subPrefix := concatPrefix(prefix, ch.Name()) // Get globals out of dest and merge them into dvmap. - coalesceGlobals(printf, dvmap, dest, subPrefix, merge) + err = coalesceGlobals(printf, dvmap, dest, subPrefix, merge) + if err != nil { + return dest, err + } // Now coalesce the rest of the values. var err error dest[sub.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge) @@ -136,21 +139,21 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi // coalesceGlobals copies the globals out of src and merges them into dest. // // For convenience, returns dest. -func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) { +func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) error { var dg, sg map[string]any if destglob, ok := dest[common.GlobalKey]; !ok { dg = make(map[string]any) } else if dg, ok = destglob.(map[string]any); !ok { printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey) - return + return nil } if srcglob, ok := src[common.GlobalKey]; !ok { sg = make(map[string]any) } else if sg, ok = srcglob.(map[string]any); !ok { printf("warning: skipping globals because source %s is not a table.", common.GlobalKey) - return + return nil } // EXPERIMENTAL: In the past, we have disallowed globals to test tables. This @@ -159,8 +162,15 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ // tables in globals. for key, val := range sg { if istable(val) { - valCopy, _ := copystructure.Copy(val) - vv := valCopy.(map[string]interface{}) + valCopy, err := copystructure.Copy(val) + if err != nil { + return err + } + vv, ok := valCopy.(map[string]any) + if !ok { + printf("warning: unable to convert globals copy to Helm values type") + continue + } if destv, ok := dg[key]; !ok { // Here there is no merge. We're just adding. dg[key] = vv @@ -187,6 +197,7 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ } } dest[common.GlobalKey] = dg + return nil } From e9736f6a6f2be22c73f6a9ac95123889d8b8b97f Mon Sep 17 00:00:00 2001 From: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Date: Sat, 7 Mar 2026 01:50:06 +0530 Subject: [PATCH 3/7] Incorporating suggested changes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index 8bafcd18e..a861e0357 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -164,7 +164,8 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ if istable(val) { valCopy, err := copystructure.Copy(val) if err != nil { - return err + fullPath := concatPrefix(prefix, key) + return fmt.Errorf("copying globals for %s: %w", fullPath, err) } vv, ok := valCopy.(map[string]any) if !ok { From 4c98ef3804757020f2255e75b622850093f6f289 Mon Sep 17 00:00:00 2001 From: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Date: Sat, 7 Mar 2026 01:53:57 +0530 Subject: [PATCH 4/7] Incorporating suggested changes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index a861e0357..8d30b3afb 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -137,8 +137,6 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi } // coalesceGlobals copies the globals out of src and merges them into dest. -// -// For convenience, returns dest. func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) error { var dg, sg map[string]any From f6c70a2cf6db104a15dda5fd49dbbefd45486025 Mon Sep 17 00:00:00 2001 From: antyagi Date: Sat, 7 Mar 2026 16:16:00 +0530 Subject: [PATCH 5/7] fix issue with go lint Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index 8d30b3afb..b89578f4b 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -199,7 +199,6 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ return nil } - // coalesceValues builds up a values map for a particular chart. // // Values in v will override the values in the chart. From 13eaf7af0b753590b860eeb34a26f2b0a0ff4c3b Mon Sep 17 00:00:00 2001 From: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:05:46 +0530 Subject: [PATCH 6/7] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> --- pkg/chart/common/util/coalesce.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index b89578f4b..9ecd046f9 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -121,12 +121,10 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi dvmap := dv.(map[string]any) subPrefix := concatPrefix(prefix, ch.Name()) // Get globals out of dest and merge them into dvmap. - err = coalesceGlobals(printf, dvmap, dest, subPrefix, merge) - if err != nil { + if err := coalesceGlobals(printf, dvmap, dest, subPrefix, merge); err != nil { return dest, err } // Now coalesce the rest of the values. - var err error dest[sub.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge) if err != nil { return dest, err From 94e12130a5a0c3db72b71a35574646a6bd903b73 Mon Sep 17 00:00:00 2001 From: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:08:05 +0530 Subject: [PATCH 7/7] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Anubhav_Tyagi <76842675+AnubhavT007@users.noreply.github.com> --- pkg/chart/common/util/coalesce.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index 9ecd046f9..7d40c0a0e 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -168,6 +168,10 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ printf("warning: unable to convert globals copy to Helm values type") continue } + // Ensure vv is a non-nil map so that merges into it are not lost. + if vv == nil { + vv = make(map[string]any) + } if destv, ok := dg[key]; !ok { // Here there is no merge. We're just adding. dg[key] = vv