Skip to content

proposal: text/template,html/template: Template.ExecuteLite skip resolution to methods to allow DCE #72895

Description

@seankhliao

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

Activity

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

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    • Status
      Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions