SYSTEM Cited by 1 source
text/template¶
text/template is Go's standard-library templating package
(pkg.go.dev/text/template).
Executes text templates that interpolate fields + method calls on
arbitrary data values, e.g. {{ .Error }} to call the Error()
method of the piped value.
Why it matters for binary size¶
Internally, template execution uses
reflect.MethodByName(name) with name taken from the template
AST at runtime — i.e. a non-constant name. This is the
canonical real-world offender that
disables the Go
linker's method dead-code elimination: the linker can't know
which methods the template engine will resolve, so every exported
method of every reachable type stays in the binary.
html/template is a direct user of text/template and inherits the same property.
Datadog's workaround¶
Rather than wait on the open [Go issue
72895](https://github.com/golang/go/issues/72895) to add a¶
static-disable mechanism, Datadog forked both packages into
pkg/template/
and patched the method-call code path to be statically disabled.
This — combined with patches to ~a dozen other dependencies'
reflect.MethodByName uses and full re-enabling of method DCE
across all binaries — yielded 16-25 % per binary / ~100 MiB
total on Linux amd64.
Caveat¶
Forking stdlib is a long-term maintenance cost. Not every team
should fork text/template — most can audit individual
reflect.MethodByName call sites, scope method-DCE to binaries
that don't use templates, or wait for the upstream fix.
Seen in¶
- sources/2026-02-18-datadog-how-we-reduced-agent-go-binaries-up-to-77-percent — canonical wiki instance as the method-DCE-blocking stdlib package that Datadog forked.