Open
Description
Proposal Details
Use of reflect.Value.Method or reflect.Value.MethodByName disables dead code elimination in the linker as it cannot know needs to kept around vs what can be dropped.
text/template
and by extension html/template
are perhaps the main paths through which these methods become reachable in programs written in Go.
This leads to issues like:
- x/net/trace: dependency on html/template inhibits dead code elimination #62024: x/net/trace: dependency on html/template inhibits dead code elimination
- Allow linker to perform deadcode elimination for program using Cobra spf13/cobra#1956 cobra using text/template disable DCE
I assert that many using of text/template only need to operate on static data (precomputed struct fields, maps, slices).
A new method for template execution that skips attempting to resolve arguments to methods could work for a majority of users while still enabling DCE.
package template
// ExecuteLite executes the named template like [Template.ExecuteTemplate]
// except that arguments are not resolved to methods. For example:
//
// {{ .Foo }}
//
// Would resolve to a struct field named "Foo", or a map with the key "Foo",
// but not a method named "Foo".
//
// Exclusive use of [Template.ExecuteLite] in rendering templates allows the compiler
// to perform dead code elimination.
func (t *Template) ExecuteLite(w io.Writer, name string, data any) error
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming