← Back to Pull requests

docs(v2): add binary size guide and mkdocs navigation for v2 build tags #2456

Closed
AdamMagued closed this pull request without merging on Oct 09, 2026 06:53 UTC
View on GitHub
AdamMagued AdamMagued commented on Oct 05, 2026 00:32 UTC
Author

What type of PR is this?

  • documentation
  • What this PR does / why we need it:

    Adds a dedicated v2 binary size guide covering build flags (-trimpath, -ldflags="-s -w") and compile-time tags (urfave_cli_no_docs and urfave_cli_no_suggest), and registers it in mkdocs navigation.

    Which issue(s) this PR fixes:

    ~~Fixes #2365~~

    Special notes for your reviewer:

    None.

    Testing

    Verified documentation structure and mkdocs YAML syntax. All package unit tests, vet checks, and binary size checks pass cleanly in sandbox isolation.

    Release Notes

    Add binary size optimization guide and build flag reference for v2

    Diff: 86 lines (+86 / -0) across 2 files Reviewer: kolyshkin Review duration: 6140m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.31) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.31 · 86 lines diff across 2 files
    0.31
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.71 · 5 substantive comment(s)
    0.71
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    79%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.267
    Real PR Conversation Timeline
    20 items
    greptile-apps[bot] greptile-apps[bot] commented on Oct 05, 2026 00:35 UTC
    Bot

    <!-- greptile_summary -->

    <h2><a href="https://app.greptile.com/api/retrigger?id=74546391"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a>Confidence Score: 4/5</h2>

    [Low risk] Expands binary size optimization documentation\.

    The PR should not merge until the v3 custom-template guidance covers commands with ExtraInfo.

    <h2>Findings</h2>

    1. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top">&nbsp;Custom printer can be bypassed <a href="https://github.com/urfave/cli/pull/2456#discussion_r4179954760">▶</a>
    2. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top">&nbsp;Stripped binary has no symbols <a href="https://github.com/urfave/cli/pull/2456#discussion_r4179954754">▶</a>
    3. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top">&nbsp;Symbols sorted by address <a href="https://github.com/urfave/cli/pull/2456#discussion_r4179954758">▶</a>

    <details><summary>Summary</summary>

    The PR adds a v2 binary-size guide and navigation entry, and expands the v3 guide with build flags, linker diagnostics, feature-pruning examples, and compression trade-offs.

  • The new v2 symbol-inspection workflow needs an unstripped binary and a size-field sort.

  • The v3 custom-printer guidance misses the ExtraInfo help path.

  • </details>

    <!-- greptile_confidence_score:4 -->

    <sub>Reviews (1) · Last reviewed commit: "docs: expand binary size optimization gu..."</sub>

    greptile-apps[bot] greptile-apps[bot] commented on code on Oct 05, 2026 00:35 UTC
    Code Review
    docs/v2/binary-size.md:1
    @@ -0,0 +1,85 @@
    +# Binary Size
    +
    +Go removes unreachable code during compilation. The first step in size optimization
    +is to measure the shipped executable rather than assuming a feature introduces overhead.
    +
    +```sh-session
    +go build -trimpath -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +## Compiler and Linker Flags
    +
    +For production releases, combine path trimming with symbol table and debugging removal:
    +
    +```sh-session
    +go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +### Flag Breakdown
    +
    +- `-trimpath`: Strips local file system paths from the compiled executable. This removes
    +  machine-specific directory paths from panic stack traces, produces reproducible
    +  binaries, and reduces string data size.
    +- `-ldflags="-s -w"`: Passes flags to the Go linker:
    +    - `-s`: Omits the symbol table. This removes symbol names and type metadata.
    +    - `-w`: Omits DWARF debugging information. This removes line numbers and debug
    +      tables used by external debuggers.
    +
    +Panic stack traces retain function names and line offsets because the Go runtime
    +maintains internal program counter tables in a distinct section.
    +
    +## Build Tags in v2
    +
    +In `urfave/cli/v2`, two build tags prune optional dependencies and features at compile time:
    +
    +| Build Tag | Target Feature | Dependency Removed | Approximate Savings |
    +|-----------|----------------|--------------------|---------------------|
    +| `urfave_cli_no_docs` | Markdown and man page generation (`ToMarkdown`, `ToMan`) | Documentation generator packages | 300 to 400 KB |
    +| `urfave_cli_no_suggest` | Command and flag typo suggestions ("Did you mean?") | `github.com/xrash/smetrics` | Variable |
    +
    +### Usage
    +
    +To build without documentation generation methods:
    +
    +```sh-session
    +go build -tags urfave_cli_no_docs -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To build without typo suggestions:
    +
    +```sh-session
    +go build -tags urfave_cli_no_suggest -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To combine both build tags:
    +
    +```sh-session
    +go build -tags "urfave_cli_no_docs urfave_cli_no_suggest" -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +## Inspecting Binary Contents
    +
    +Use the Go toolchain to inspect embedded build metadata and symbol allocations:
    +
    +```sh-session
    +go version -m myapp
    +go tool nm -size myapp | sort -nr | head -40

    <a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Stripped binary has no symbols
    The preceding build uses -s, which removes the symbol table from myapp. Running go tool nm on that binary reports no symbols, so readers cannot inspect allocations as instructed. The guide needs an unstripped build for this step.

    greptile-apps[bot] greptile-apps[bot] commented on code on Oct 05, 2026 00:35 UTC
    Code Review
    docs/v2/binary-size.md:1
    @@ -0,0 +1,85 @@
    +# Binary Size
    +
    +Go removes unreachable code during compilation. The first step in size optimization
    +is to measure the shipped executable rather than assuming a feature introduces overhead.
    +
    +```sh-session
    +go build -trimpath -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +## Compiler and Linker Flags
    +
    +For production releases, combine path trimming with symbol table and debugging removal:
    +
    +```sh-session
    +go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +### Flag Breakdown
    +
    +- `-trimpath`: Strips local file system paths from the compiled executable. This removes
    +  machine-specific directory paths from panic stack traces, produces reproducible
    +  binaries, and reduces string data size.
    +- `-ldflags="-s -w"`: Passes flags to the Go linker:
    +    - `-s`: Omits the symbol table. This removes symbol names and type metadata.
    +    - `-w`: Omits DWARF debugging information. This removes line numbers and debug
    +      tables used by external debuggers.
    +
    +Panic stack traces retain function names and line offsets because the Go runtime
    +maintains internal program counter tables in a distinct section.
    +
    +## Build Tags in v2
    +
    +In `urfave/cli/v2`, two build tags prune optional dependencies and features at compile time:
    +
    +| Build Tag | Target Feature | Dependency Removed | Approximate Savings |
    +|-----------|----------------|--------------------|---------------------|
    +| `urfave_cli_no_docs` | Markdown and man page generation (`ToMarkdown`, `ToMan`) | Documentation generator packages | 300 to 400 KB |
    +| `urfave_cli_no_suggest` | Command and flag typo suggestions ("Did you mean?") | `github.com/xrash/smetrics` | Variable |
    +
    +### Usage
    +
    +To build without documentation generation methods:
    +
    +```sh-session
    +go build -tags urfave_cli_no_docs -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To build without typo suggestions:
    +
    +```sh-session
    +go build -tags urfave_cli_no_suggest -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To combine both build tags:
    +
    +```sh-session
    +go build -tags "urfave_cli_no_docs urfave_cli_no_suggest" -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +## Inspecting Binary Contents
    +
    +Use the Go toolchain to inspect embedded build metadata and symbol allocations:
    +
    +```sh-session
    +go version -m myapp
    +go tool nm -size myapp | sort -nr | head -40

    <a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Symbols sorted by address
    go tool nm -size prints the address before the size, so sort -nr ranks addresses, not footprints. Even with an unstripped binary, the first 40 results are not necessarily the largest symbols, making the size investigation misleading. Sort on the size field instead.

    go tool nm -size myapp | sort -k2,2nr | head -40
    

    greptile-apps[bot] greptile-apps[bot] commented on code on Oct 05, 2026 00:35 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -1,186 +1,294 @@
     # Binary Size
     
    -Go removes unreachable code during compilation, so the first step is to
    -measure the binary you ship instead of assuming a specific feature is expensive.
    +Go removes unreachable code during compilation. The first step in size optimization
    +is to measure the shipped executable rather than assuming a feature introduces overhead.
     
     ```sh-session
     go build -trimpath -o myapp ./cmd/myapp
     ls -lh myapp
     ```
     
    -For a release-style build, combine reproducible paths with stripped symbol and
    -debug information:
    +## Compiler and Linker Flags
    +
    +For production builds, combine path trimming with symbol table and debugging removal:
     
     ```sh-session
     go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
     ls -lh myapp
     ```
     
    -Use the Go toolchain to inspect what is in the binary:
    +### Flag Breakdown
    +
    +- `-trimpath`: Strips local file system paths from the compiled executable. This removes
    +  personal directory structures and machine-specific metadata, produces reproducible
    +  binaries, and reduces string data size.
    +- `-ldflags="-s -w"`: Passes flags to the Go linker:
    +    - `-s`: Omits the symbol table. This removes symbol names and type metadata.
    +    - `-w`: Omits DWARF debugging information. This removes line numbers and debug
    +      tables used by external debuggers.
    +
    +### Operational Trade-offs
    +
    +Stripping DWARF metadata prevents external debuggers like GDB from resolving line numbers
    +or inspecting variable state. Panic stack traces still include function names and line
    +offsets because the Go runtime preserves internal program counter tables in a distinct section.
    +
    +## Inspecting Binary Contents
    +
    +Use the Go toolchain to inspect embedded build metadata and symbol allocations:
     
     ```sh-session
     go version -m myapp
     go tool nm -size myapp | sort -nr | head -40
     ```
     
    +- `go version -m`: Displays module dependencies, Go toolchain version, build tags, and
    +  compiler flags embedded in the binary.
    +- `go tool nm -size`: Lists symbols sorted by footprint, identifying the largest functions
    +  and data structures in an unstripped binary.
    +
     ## Practical Checks
     
    -- Run `make check-binary-size` in this repository to compare the current package
    -  contribution against the tracked binary-size budget.
    +- Run `make check-binary-size` in this repository to compare package contribution against
    +  the tracked binary-size budget.
     - Build with `-trimpath` for reproducible paths.
    -- Use `-ldflags="-s -w"` for release builds when debug symbols are not needed.
    -- Keep optional integrations in separate packages when they bring large
    -  dependencies.
    -- Avoid adding reflection-heavy dependencies to the main command package unless
    -  they are required at runtime.
    -- Compare sizes from clean builds after each change.
    -
    -If a specific `urfave/cli` feature appears to keep unexpected code reachable,
    -[open an issue](https://github.com/urfave/cli/issues/new) with the Go version,
    -build command, a minimal reproduction, and the `go tool nm -size` output that
    -shows the largest symbols.
    +- Use `-ldflags="-s -w"` for production builds when debug metadata is unnecessary.
    +- Isolate optional integrations into separate packages when they introduce large dependencies.
    +- Avoid reflection-heavy packages in the primary command path when runtime inspection is unnecessary.
    +- Compare sizes from clean builds after each modification.
    +
    +If a specific `urfave/cli` feature retains unexpected unreachable code,
    +[open an issue](https://github.com/urfave/cli/issues/new) with the Go version, build
    +command, minimal reproduction, and `go tool nm -size` output displaying the largest symbols.
     
     ## Deeper Analysis with go-size-analyzer
    - 
    -The commands above show symbol-level sizes, but they do not clearly show which
    -packages contribute most to the binary. [go-size-analyzer](https://github.com/Zxilly/go-size-analyzer)
    -provides a package-level breakdown.
    - 
    -Install it with:
    - 
    +
    +The standard toolchain commands show symbol sizes, but do not attribute footprint by package.
    +The [go-size-analyzer](https://github.com/Zxilly/go-size-analyzer) utility provides a package-level breakdown.
    +
    +Install the utility:
    +
     ```sh-session
     go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
     ```
    - 
    -Then analyze a binary:
    - 
    +
    +Analyze the target binary:
    +
     ```sh-session
     gsa myapp
     ```
    - 
    -For example, a minimal `urfave/cli/v3` binary showed:
    - 
    +
    +Example output for a minimal `urfave/cli/v3` application:
    +
     ```
     21.58%  runtime                  1.0 MB
      6.57%  reflect                  315 kB
      6.25%  .rodata                  300 kB
      5.87%  github.com/urfave/cli/v3 282 kB
      5.74%  text/template            275 kB
     ```
    - 
    -This helps identify which packages are worth investigating. Packages such as
    -`runtime` are fundamental to a Go binary and are not normally removable.
    -For an interactive view, use:
    - 
    +
    +This output isolates the packages with the largest contributions. Foundational runtime
    +components like `runtime` remain mandatory for Go executables.
    +
    +For terminal navigation, pass the `--tui` flag:
    +
     ```sh-session
     gsa --tui myapp
     ```
    - 
    -> **Note:** analyze an unstripped binary when possible. Stripping debug
    -> information can make package attribution less accurate.
    - 
    +
    +> **Note:** Analyze an unstripped binary. Stripping debug tables limits package attribution accuracy.
    +
     ## Dependency Versions and Multiple Modules
    - 
    -A repository may contain multiple Go modules, each with its own `go.mod`.
    -Check the modules and their selected versions with:
    - 
    +
    +A repository can maintain multiple Go modules, each defining its own `go.mod`.
    +Inspect resolved module versions with:
    +
     ```sh-session
     go list -m all
     ```
    - 
    -For a specific dependency:
    - 
    +
    +To inspect a specific dependency:
    +
     ```sh-session
     go list -m -json github.com/urfave/cli/v3
     ```
    - 
    -Go's module resolution (Minimal Version Selection) picks a single version of
    -each module path per main module build, so differing `go.mod` files do not by
    -themselves cause duplicate versions of the same module in a given binary.
    -This mainly matters when comparing binaries built from *different* main
    -modules, since each one resolves versions independently — so check the
    -actual selected version rather than relying only on the version written in
    -`go.mod`. For example, the documentation module uses:
    - 
    +
    +Go Minimal Version Selection (MVS) selects a single version of each module path per
    +build. Differing `go.mod` files do not duplicate identical module paths within a single
    +compiled executable. Discrepancies arise when comparing binaries compiled from distinct
    +root modules. Check the selected module version instead of relying on individual `go.mod`
    +declarations. For example, the documentation module uses:
    +
     ```
     replace github.com/urfave/cli/v3 => ../
     ```
    - 
    -so it builds against the local `urfave/cli/v3` checkout.
    - 
    -## Reflection and Templates
    - 
    -Reflection and templates can contribute noticeably to binary size because additional type information and supporting code may remain reachable. In the analyzer output, `reflect` and `text/template` are among the larger contributors.
    - 
    -`urfave/cli/v3` uses templates for help rendering, making `text/template` one
    -of the packages worth investigating when analyzing binary size. These numbers
    -show their contribution to the analyzed binary, but do not by themselves
    -prove that all of this code comes from a single feature.
    -
    -See [`urfave_cli_no_template`](#urfave_cli_no_template) for a way to avoid
    -linking `text/template`.
    - 
    -## Hiding Built-in Help
    - 
    -Disabling built-in help does not currently reduce the binary size.
    - 
    -Two otherwise identical binaries were built:
    - 
    -```go
    -&cli.Command{}
    +
    +This builds against the local repository checkout.
    +
    +## Dead Code Elimination and Reflection
    +
    +Go performs dead code elimination (DCE) at link time to drop unreachable functions.
    +Dynamic reflection impedes this optimization. When an application calls `reflect.Value.Method`
    +or `reflect.Type.MethodByName` with a non-constant parameter, the linker cannot determine which
    +exported methods may run. Consequently, the linker retains all exported methods of all
    +reachable types across the entire program (see [golang/go#72895](https://github.com/golang/go/issues/72895)).
    +
    +The standard library `text/template` package evaluates template methods via reflection,
    +triggering this linker constraint.
    +
    +### Proving Dead Code Elimination Status
    +
    +To verify whether dead code elimination of exported methods is disabled, inspect the linker
    +dependency graph with `-dumpdep`:
    +
    +```sh-session
    +go build -ldflags=-dumpdep -o /dev/null ./cmd/myapp 2>&1 | grep '<ReflectMethod>'
     ```
    - 
    -and:
    - 
    +
    +If `<ReflectMethod>` entries appear in the output, the linker preserved exported methods across
    +the binary. Eliminating dynamic reflection removes `<ReflectMethod>` and allows the linker
    +to discard unreferenced exported methods.
    +
    +## Current v3 Build Tags
    +
    +### `urfave_cli_no_template`
    +
    +The `urfave_cli_no_template` build tag renders default help text and fish shell completions
    +in Go code without using `text/template`. This removes the dynamic reflection call site,
    +allowing the linker to execute dead code elimination across the application:
    +
    +```sh-session
    +go build -tags urfave_cli_no_template -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +When compiled with this tag, `examples/example-cli` drops from 5.1 MB to 3.2 MB unstripped.
    +
    +#### Constraints
    +
    +- The default help and fish completion outputs remain byte-for-byte identical.
    +- Custom templates are unsupported. The template constants `RootCommandHelpTemplate`,
    +  `CommandHelpTemplate`, `SubcommandHelpTemplate`, and `FishCompletionTemplate` are fixed
    +  strings indicating help modes. Modifying them causes a compile error.
    +- Passing custom templates to the default help printer causes a panic. Applications
    +  requiring custom template rendering must supply a custom `HelpPrinter`.

    <a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> Custom printer can be bypassed
    When a command has ExtraInfo, root help calls HelpPrinterCustom directly rather than the application's replacement HelpPrinter. With urfave_cli_no_template and a custom template, following this workaround still reaches the default printer and panics. These applications also need to replace HelpPrinterCustom or avoid that help path.

    kolyshkin kolyshkin requested changes on Oct 05, 2026 06:24 UTC
    Changes Requested Reviewer

    The patch looks way too broad, changing lots of files at once, without explaining why, and is thus very hard to review.

    If you can write more focused patch series, like:
    - add this;
    - fix that;
    - change the wording in such-and-such section

    that would be easier to review.

    AdamMagued AdamMagued commented on Oct 05, 2026 15:44 UTC
    Author

    @kolyshkin I split the PR into five focused commits:

    1. docs(v3): fix symbol sorting and clarify unstripped binary requirement for nm: fixes the go tool nm -size sort key (-k2,2nr instead of -nr) and notes that -s strips symbol tables.
    2. docs(v3): document linker dead code elimination diagnostic with dumpdep: documents using go build -ldflags=-dumpdep to detect <ReflectMethod> when testing dead code elimination status.
    3. docs(v3): clarify urfave_cli_no_template constraints and ExtraInfo handling: details template immutability, default printer panics, and the requirement to override HelpPrinterCustom when commands define ExtraInfo.
    4. docs(v2): add binary size guide for v2 build tags: adds docs/v2/binary-size.md covering -trimpath, -ldflags="-s -w", and the v2 tags urfave_cli_no_docs and urfave_cli_no_suggest.
    5. docs: register v2 binary size guide in mkdocs navigation: adds the v2 guide to mkdocs.yml.

    I also dropped the generic UPX and pprof examples to keep the diff limited to urfave/cli specifics (+146 -21 total diff).

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:03 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -16,13 +16,17 @@ go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
     ls -lh myapp
     ```
     
    -Use the Go toolchain to inspect what is in the binary:
    +Use the Go toolchain to inspect what is in an unstripped binary:
     
     ```sh-session
     go version -m myapp
    -go tool nm -size myapp | sort -nr | head -40
    +go tool nm -size myapp | sort -k2,2nr | head -40
     ```
     
    +> **Note:** The `-s` flag strips the symbol table. Run `go tool nm` against

    Which -s flag? I mean, I understand that you talk about ldflags from the previous step, but I doubt it's easy to get for every other reader.

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:04 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -16,13 +16,17 @@ go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
     ls -lh myapp
     ```
     
    -Use the Go toolchain to inspect what is in the binary:
    +Use the Go toolchain to inspect what is in an unstripped binary:
     
     ```sh-session
     go version -m myapp
    -go tool nm -size myapp | sort -nr | head -40
    +go tool nm -size myapp | sort -k2,2nr | head -40
     ```
     
    +> **Note:** The `-s` flag strips the symbol table. Run `go tool nm` against
    +> an unstripped binary. `sort -k2,2nr` sorts by symbol size (the second column)
    +> rather than address.

    I think it does not need to be explained.

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:04 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -98,7 +102,7 @@ Go's module resolution (Minimal Version Selection) picks a single version of
     each module path per main module build, so differing `go.mod` files do not by
     themselves cause duplicate versions of the same module in a given binary.
     This mainly matters when comparing binaries built from *different* main
    -modules, since each one resolves versions independently — so check the
    +modules, since each resolves versions independently; check the

    How is this an improvement? You just change the text arbitrarily

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:06 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -123,6 +123,29 @@ prove that all of this code comes from a single feature.
     
     See [`urfave_cli_no_template`](#urfave_cli_no_template) for a way to avoid
     linking `text/template`.
    +
    +### Proving Dead Code Elimination Status
    +
    +Go removes unreachable functions at link time via dead code elimination (DCE).
    +When a program calls dynamic reflection methods such as `reflect.Value.Method` or
    +`reflect.Type.MethodByName` with variable arguments, the linker cannot determine
    +which exported methods might run. The linker then retains all exported methods
    +across all reachable types throughout the entire program (see
    +[golang/go#72895](https://github.com/golang/go/issues/72895)).
    +
    +The standard library `text/template` package evaluates template methods via
    +dynamic reflection, triggering this linker behavior.

    You repeat what was said a few lines above (in Reflection and Templates), why?

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:06 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -177,37 +177,49 @@ sizes for the relevant packages:
      
     `HideHelp` and `HideHelpCommand` are runtime options, so hiding help does not
     remove the help implementation from the compiled binary. If reducing this
    -overhead is important, a compile-time approach — such as separate build
    -configurations or changes to the library — would be required.
    +overhead is important, a compile-time approach, such as separate build
    +configurations or changes to the library, would be required.

    why the change?

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:06 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -177,37 +177,49 @@ sizes for the relevant packages:
      
     `HideHelp` and `HideHelpCommand` are runtime options, so hiding help does not
     remove the help implementation from the compiled binary. If reducing this
    -overhead is important, a compile-time approach — such as separate build
    -configurations or changes to the library — would be required.
    +overhead is important, a compile-time approach, such as separate build
    +configurations or changes to the library, would be required.
     
     ## Current v3 Build Tags
     
     ### `urfave_cli_no_template`
     
    -Using `text/template` makes the Go linker disable dead code elimination of
    -exported methods for the whole program, since templates can call arbitrary
    +Using `text/template` causes the Go linker to disable dead code elimination of
    +exported methods for the whole program, since templates can invoke arbitrary

    why the change?

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:06 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -177,37 +177,49 @@ sizes for the relevant packages:
      
     `HideHelp` and `HideHelpCommand` are runtime options, so hiding help does not
     remove the help implementation from the compiled binary. If reducing this
    -overhead is important, a compile-time approach — such as separate build
    -configurations or changes to the library — would be required.
    +overhead is important, a compile-time approach, such as separate build
    +configurations or changes to the library, would be required.
     
     ## Current v3 Build Tags
     
     ### `urfave_cli_no_template`
     
    -Using `text/template` makes the Go linker disable dead code elimination of
    -exported methods for the whole program, since templates can call arbitrary
    +Using `text/template` causes the Go linker to disable dead code elimination of
    +exported methods for the whole program, since templates can invoke arbitrary
     methods by name (see [golang/go#72895](https://github.com/golang/go/issues/72895)).
    -For larger programs, this can noticeably increase the binary size.
    +For larger programs, this can noticeably increase binary size.

    why?

    kolyshkin kolyshkin commented on code on Oct 05, 2026 19:07 UTC
    Code Review
    docs/v3/binary-size.md:1
    @@ -177,37 +177,49 @@ sizes for the relevant packages:
      
     `HideHelp` and `HideHelpCommand` are runtime options, so hiding help does not
     remove the help implementation from the compiled binary. If reducing this
    -overhead is important, a compile-time approach — such as separate build
    -configurations or changes to the library — would be required.
    +overhead is important, a compile-time approach, such as separate build
    +configurations or changes to the library, would be required.
     
     ## Current v3 Build Tags
     
     ### `urfave_cli_no_template`
     
    -Using `text/template` makes the Go linker disable dead code elimination of
    -exported methods for the whole program, since templates can call arbitrary
    +Using `text/template` causes the Go linker to disable dead code elimination of
    +exported methods for the whole program, since templates can invoke arbitrary
     methods by name (see [golang/go#72895](https://github.com/golang/go/issues/72895)).
    -For larger programs, this can noticeably increase the binary size.
    +For larger programs, this can noticeably increase binary size.
     
     With the `urfave_cli_no_template` build tag, the default help and fish
    -completion are rendered without `text/template`, producing the same output,
    -and dead code elimination is no longer disabled:
    +completion render without `text/template`, producing identical output,
    +and dead code elimination remains active:

    you just arbitrarily rephrased it, why?

    kolyshkin kolyshkin requested changes on Oct 05, 2026 19:09 UTC
    Changes Requested Reviewer

    I would only leave commit 4 ("docs(v2): add binary size guide for v2 build tags") -- if we still care for v2 (do we)?

    As for the rest, I would drop (or rework, considerably) it. It looks like the objective here was to maximize the amount of changes, and not fix the issues with the current doc.

    AdamMagued AdamMagued commented on Oct 06, 2026 13:47 UTC
    Author

    @kolyshkin I dropped the v3 documentation changes and squashed the branch into a single commit. This PR now keeps docs/v2/binary-size.md and the navigation entry in mkdocs.yml.

    kolyshkin kolyshkin commented on code on Oct 08, 2026 05:05 UTC
    Code Review
    docs/v2/binary-size.md:1
    @@ -0,0 +1,85 @@
    +# Binary Size
    +
    +Go removes unreachable code during compilation. The first step in size optimization
    +is measuring the shipped executable rather than assuming a feature introduces overhead.
    +
    +```sh-session
    +go build -trimpath -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +## Compiler and Linker Flags
    +
    +For release builds, combine path trimming with symbol table and debug metadata removal:
    +
    +```sh-session
    +go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +ls -lh myapp
    +```
    +
    +### Flag Breakdown
    +
    +- `-trimpath`: Strips local file system paths from the compiled executable. This removes
    +  machine-specific directory paths from panic stack traces, produces reproducible
    +  binaries, and reduces string data size.
    +- `-ldflags="-s -w"`:
    +  - `-s`: Omits the symbol table.
    +  - `-w`: Omits DWARF debugging information.
    +
    +Panic stack traces retain function names and line offsets because the Go runtime
    +maintains internal program counter tables in a distinct section.
    +
    +## Inspecting Binary Contents
    +
    +Use the Go toolchain to inspect embedded build metadata and symbol allocations on an unstripped binary:
    +
    +```sh-session
    +go version -m myapp
    +go tool nm -size myapp | sort -k2,2nr | head -40
    +```
    +
    +- `go version -m`: Displays module dependencies, Go toolchain version, build tags, and
    +  compiler flags embedded in the binary.
    +- `go tool nm -size`: Lists symbols sorted by size, identifying the largest functions
    +  and data structures. Run this command against an unstripped binary, as `-s` removes
    +  the symbol table.
    +
    +## Build Tags in v2
    +
    +In `urfave/cli/v2`, two build tags prune optional dependencies and features at compile time:
    +
    +| Build Tag | Target Feature | Dependency Removed | Approximate Savings |
    +|-----------|----------------|--------------------|---------------------|
    +| `urfave_cli_no_docs` | Markdown and man page generation (`ToMarkdown`, `ToMan`) | Documentation generator packages | 300 to 400 KB |
    +| `urfave_cli_no_suggest` | Command and flag typo suggestions ("Did you mean?") | `github.com/xrash/smetrics` | Variable |
    +
    +### Usage
    +
    +To build without documentation generation methods:
    +
    +```sh-session
    +go build -tags urfave_cli_no_docs -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To build without typo suggestions:
    +
    +```sh-session
    +go build -tags urfave_cli_no_suggest -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```
    +
    +To combine both build tags:
    +
    +```sh-session
    +go build -tags "urfave_cli_no_docs urfave_cli_no_suggest" -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
    +```

    Twenty lines of code to show how to use a build tag seems excessive to me. I would omit all this.

    kolyshkin kolyshkin requested changes on Oct 08, 2026 05:14 UTC
    Changes Requested Reviewer

    Still feels like too much to me. Teaching users how to compile a go program, use build tags, and using ls -lh should not be part of urfave/cli docs.

    Once the above is removed, what's left is:
    1. v2 build tags
    2. Using go version -m and go tool nm -size

    Of that, v2 build tags are already described in docs/index.md (in v2-maint branch), and go version -m and go tool nm are in no way urfave/cli specific (but are described in v3/binary-size.md).

    So I'm not sure this PR adds value.

    I am not a maintainer so feel free to ignore.

    Juneezee Juneezee commented on Oct 09, 2026 06:53 UTC
    Contributor

    Thanks @kolyshkin for taking the time to review this.

    @AdamMagued We are no longer updating the V1 or V2 documentation. These are legacy versions and we have no plans to maintain or update them going forward, except for critical security fixes.

    Reviewers
    Assignees
    AdamMagued AdamMagued
    Labels
    risk: low confidence: 79.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.2% (LOW) · Higher = larger blast radius
    31.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 79.8% · Lower = rushed or shallow review
    79.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.3% · Safe to merge
    6.3%
    Repository