Skip to content

The use of text/template disables dead code elimination in all users of cobra #2015

Closed
@artem-anisimov-0x7f

Description

@artem-anisimov-0x7f

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 is a very notable offender in this respect. It calls MethodByName() with random strings extracted from template texts.

Command::UsageFunc() and Command::HelpFunc() use text/template, hence they disable the DCE for all users of cobra. Since cobra is the go-to module to implement CLIs, this essentially disables DCE in all command line tools written in go.

A low-level library that is used by almost everyone should not pessimise the code generation by disabling the DCE. I'd avoid text/template altogether.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions