Debian Codegraph @

docs/v3/binary-size.md

raw symbols SCIP
1 # Binary Size
2
3 Go removes unreachable code during compilation, so the first step is to
4 measure the binary you ship instead of assuming a specific feature is expensive.
5
6 ```sh-session
7 go build -trimpath -o myapp ./cmd/myapp
8 ls -lh myapp
9 ```
10
11 For a release-style build, combine reproducible paths with stripped symbol and
12 debug information:
13
14 ```sh-session
15 go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
16 ls -lh myapp
17 ```
18
19 Use the Go toolchain to inspect what is in the binary:
20
21 ```sh-session
22 go version -m myapp
23 go tool nm -size myapp | sort -nr | head -40
24 ```
25
26 ## Practical Checks
27
28 - Run `make check-binary-size` in this repository to compare the current package
29 contribution against the tracked binary-size budget.
30 - Build with `-trimpath` for reproducible paths.
31 - Use `-ldflags="-s -w"` for release builds when debug symbols are not needed.
32 - Keep optional integrations in separate packages when they bring large
33 dependencies.
34 - Avoid adding reflection-heavy dependencies to the main command package unless
35 they are required at runtime.
36 - Compare sizes from clean builds after each change.
37
38 If a specific `urfave/cli` feature appears to keep unexpected code reachable,
39 [open an issue](https://github.com/urfave/cli/issues/new) with the Go version,
40 build command, a minimal reproduction, and the `go tool nm -size` output that
41 shows the largest symbols.
42
43 ## Current v3 Build Tags
44
45 The v3 module does not currently define build tags such as
46 `urfave_cli_no_docs`, `urfave_cli_no_completion`, or `urfave_cli_minimal`.
47 Documentation generation lives outside the core module in
48 [`urfave/cli-docs`](https://github.com/urfave/cli-docs), so applications that
49 only import `github.com/urfave/cli/v3` do not pull in that package.
50
51 Shell completion support is part of the core package. Leave
52 `EnableShellCompletion` disabled unless the application needs shell completion,
53 then measure the result with the commands above.