From 451d264a40e3c76a68e4d7c0ae7baf2a301e631d Mon Sep 17 00:00:00 2001 From: romnn Date: Wed, 29 Apr 2026 23:06:25 +0200 Subject: [PATCH] perf(templater): skip template engine for strings without `{{` --- internal/templater/templater.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/templater/templater.go b/internal/templater/templater.go index 896cba23c1..c37bae3626 100644 --- a/internal/templater/templater.go +++ b/internal/templater/templater.go @@ -68,6 +68,13 @@ func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T { return v } + // Optimization: skip if string is not a template + if s, ok := any(v).(string); ok { + if !strings.Contains(s, "{{") { + return v + } + } + // Initialize the cache map if it's not already initialized if cache.cacheMap == nil { cache.cacheMap = cache.Vars.ToCacheMap() @@ -82,6 +89,10 @@ func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T { // Traverse the value and parse any template variables copy, err := deepcopy.TraverseStringsFunc(v, func(v string) (string, error) { + // Optimization: skip if string is not a template + if !strings.Contains(v, "{{") { + return v, nil + } tpl, err := template.New("").Funcs(templateFuncs).Parse(v) if err != nil { return v, err