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:
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
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/templateand by extensionhtml/templateare perhaps the main paths through which these methods become reachable in programs written in Go.This leads to issues like:
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.