<#7492 Compute template replacement values once pe...
# flyte-github
a
#7492 Compute template replacement values once per Render call Pull request opened by pvditt Overview
template.Render
loops over every string in a task's command and calls
render()
for each. Each
render()
call rebuilt all of the replacement values from scratch — six of which are blob-store path constructions (
GetInputPath
,
GetOutputPrefixPath
,
GetInputPrefixPath
,
GetRawOutputPrefix
,
GetPreviousCheckpointsPrefix
,
GetCheckpointPrefix
) that do URL resolution and string building — even though the values are identical for every argument. A 5-argument command built the same six paths 5×, and they were computed unconditionally as
ReplaceAllString
arguments even when the command contained no such placeholder. CPU profiling under a high-rate task-submission burst showed
template.Render
at ~34% of process CPU, with the cost inside
render()
dominated by the path getters (
GetCheckpointPrefix
~40%,
GetInputPath
~33% — i.e. the replacement-value construction, not the regex matching), and `net/url.ResolveReference`/`url.parse`/`strings.Builder` among the top allocators. This change hoists the per-call-constant replacement values into a struct computed once per
Render
call
, mirroring how
perRetryUniqueKey
was already hoisted out of the loop. The per-string work is now just the regex replacements. Notes on scope: • All six hoisted getters are pure path construction (verified against the
ioutils
implementations), so moving them out of the loop cannot change behavior — including the
prevCheckpoint == "" → "\"\""
special case, which moves up intact. •
TaskTemplatePath
(may offload/do I/O) and
Inputs.Get
(I/O) keep their existing lazy match-first behavior, unchanged. • `Render`'s exported signature is unchanged; only the unexported
render()
signature changes. Test Plan • Existing
template_test.go
suite exercises
Render
across all placeholder types and passes unchanged (
go test ./flyteplugins/go/tasks/pluginmachinery/core/template/...
), which is the right regression coverage for a pure refactor: identical inputs must produce identical outputs. •
go vet
clean. • Live before/after (2026-06-10, leaseworker on a dogfood dataplane, same fasttask tree-fanout workload at ~10–30k leases): • Without this change (control build, same day): the replacement-value construction family was the top allocator group at ~40% of a ~30 GB burst allocation delta —
net/url.(*URL).ResolveReference
7.5 GB cum,
strings.(*Builder).WriteString
4.3 GB,
net/url.parse
3.4 GB,
ensureEndingPathSeparator
1.8 GB — and
template.Render
was ~7% of burst CPU. • _With this change_: the path-construction family is absent from the top allocators across two burst rounds (t3m delta 13.7 GB and t9m delta 16.2 GB); the only remaining render cost is the per-argument regex replacement itself (~2.5 GB cum, expected — it must run per string), and
template.Render
fell below the CPU profile's reporting threshold in mid-burst 20s/30s captures. • Rendered outputs verified equivalent in practice: task submissions, log links, and input/output paths behaved identically across both builds. Rollout Plan • Merges to `main`; consuming services pick the change up on their next dependency bump/build. No config involved. Rollback Plan • Revert this commit; the change is self-contained to
template.go
and has no config, API, or persisted-state surface. 🤖 Generated with Claude Code flyteorg/flyte