golang/go

x/net/trace: dependency on html/template inhibits dead code elimination

Open

#62,024 opened on Aug 14, 2023

View on GitHub
 (24 comments) (12 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsInvestigationbinary-sizecompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Any use of reflect.Value.MethodByName() or reflect.Type.MethodByName() disables the DCE. The compiler assumes that these functions will look any method up, and cannot remove methods even if they are never called.

text/template and html/template are very notable offenders in this respect. They call MethodByName() on random strings extracted from template texts.

The package x/net/trace uses html/template, hence any user of x/net/trace compiles with DCE disabled. Worse yet, the package's init() references html/template which disables DCE even if x/net/trace is imported, but otherwise unused.

There is a very popular user of x/net/trace, namely google.golang.org/grpc. Essentially, this means that a lot of networked services in golang are compiled without DCE.

What did you expect to see?

I expect that a low-level library that is used by almost everyone does not pessimise the code generation by disabling the DCE. I'd avoid html/template altogether.

Contributor guide