docs(v2): add binary size guide and mkdocs navigation for v2 build tags #2456
<!-- 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"> 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"> 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"> 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.
ExtraInfo help path.</details>
<!-- greptile_confidence_score:4 -->
<sub>Reviews (1) · Last reviewed commit: "docs: expand binary size optimization gu..."</sub>
<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.
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Symbols sorted by addressgo 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
<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.
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.
@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).
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.
I think it does not need to be explained.
How is this an improvement? You just change the text arbitrarily
You repeat what was said a few lines above (in Reflection and Templates), why?
why the change?
why the change?
why?
you just arbitrarily rephrased it, why?
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.
@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.
Twenty lines of code to show how to use a build tag seems excessive to me. I would omit all this.
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.
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.
kolyshkin
AdamMagued
What type of PR is this?
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_docsandurfave_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