Skip to content

Template expressions are compiled on every evaluation #8136

In review

Description

@BnJam

Summary

expressions.EvaluateTemplate compiles each expression on every call (json_templates.go#L284), and compiling rebuilds expr's builtin function table each time. Evaluation itself is a small share of the cost.

Callers that pass no expr options evaluate the same few templates repeatedly:

Caller Runs
RunningPromotionsByArgoCDApplications, app name and namespace templates (indexer.go#L280, #L294) Every add/update of a Running Promotion in the informer cache
Promotion events (promotion.go#L294) Every Promotion event
Deep links (deeplinks.go#L106) Every link rendered

Measured (main @ e778d67, BenchmarkEvaluateTemplate from the fix PR, no options)

Template ns/op B/op allocs/op
main (no expression) 12 16 1
${{ vars.imageRepo }} 4,345 10,922 93
Three expressions in one string 12,271 30,838 218

Proposed change

Cache compiled programs, keyed by expression, for calls without options. Calls with options keep compiling: a program holds the functions it was compiled with (program.go#L28), and callers such as the Promotion evaluator pass functions bound to one Promotion's context.

Activity

  1. added
    kind/enhancement
    priority/normal
    area/controller
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/controllerkind/enhancementpriority/normal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions