Repository navigation
docs(v2): add binary size guide and mkdocs navigation for v2 build tags - #2456
AdamMagued wants to merge 1 commit into
Conversation
|
|
|
||
| ```sh-session | ||
| go version -m myapp | ||
| go tool nm -size myapp | sort -nr | head -40 |
There was a problem hiding this comment.
|
|
||
| ```sh-session | ||
| go version -m myapp | ||
| go tool nm -size myapp | sort -nr | head -40 |
There was a problem hiding this comment.
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 -nr | head -40 | |
| go tool nm -size myapp | sort -k2,2nr | head -40 |
| - Passing custom templates to the default help printer causes a panic. Applications | ||
| requiring custom template rendering must supply a custom `HelpPrinter`. |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
97c61ec to
b598d5c
Compare
|
@kolyshkin I split the PR into five focused commits:
I also dropped the generic UPX and pprof examples to keep the diff limited to urfave/cli specifics (+146 -21 total diff). |
| go tool nm -size myapp | sort -k2,2nr | head -40 | ||
| ``` | ||
|
|
||
| > **Note:** The `-s` flag strips the symbol table. Run `go tool nm` against |
There was a problem hiding this comment.
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.
|
|
||
| > **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. |
There was a problem hiding this comment.
I think it does not need to be explained.
| modules, since each one resolves versions independently — so check the | ||
| modules, since each resolves versions independently; check the |
There was a problem hiding this comment.
How is this an improvement? You just change the text arbitrarily
| The standard library `text/template` package evaluates template methods via | ||
| dynamic reflection, triggering this linker behavior. |
There was a problem hiding this comment.
You repeat what was said a few lines above (in Reflection and Templates), why?
| overhead is important, a compile-time approach, such as separate build | ||
| configurations or changes to the library, would be required. |
| Using `text/template` causes the Go linker to disable dead code elimination of | ||
| exported methods for the whole program, since templates can invoke arbitrary |
| 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. |
| completion render without `text/template`, producing identical output, | ||
| and dead code elimination remains active: |
There was a problem hiding this comment.
you just arbitrarily rephrased it, why?
kolyshkin
left a comment
There was a problem hiding this comment.
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.
Document compiler and linker flags (-trimpath, -ldflags="-s -w") and symbol table inspection using 'go tool nm -size' on unstripped binaries. Document v2 compile-time build tags 'urfave_cli_no_docs' and 'urfave_cli_no_suggest', their savings, and their transition to v3. Register docs/v2/binary-size.md under the v2 manual navigation in mkdocs.yml. Signed-off-by: AdamMagued <adamismailmageud@gmail.com>
b598d5c to
fa454e1
Compare
|
@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. |
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