Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/v3/binary-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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.

```sh
go build -trimpath -o myapp ./cmd/myapp
ls -lh myapp
```

For a release-style build, combine reproducible paths with stripped symbol and
debug information:

```sh
go build -trimpath -ldflags="-s -w" -o myapp ./cmd/myapp
ls -lh myapp
```

Use the Go toolchain to inspect what is in the binary:

```sh
go version -m myapp
go tool nm -size myapp | sort -nr | head -40
```

## Practical Checks

- Run `make check-binary-size` in this repository to compare the current 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.

## Current v3 Build Tags

The v3 module does not currently define build tags such as
`urfave_cli_no_docs`, `urfave_cli_no_completion`, or `urfave_cli_minimal`.
Documentation generation lives outside the core module in
[`urfave/cli-docs`](https://github.com/urfave/cli-docs), so applications that
only import `github.com/urfave/cli/v3` do not pull in that package.

Shell completion support is part of the core package. Leave
`EnableShellCompletion` disabled unless the application needs shell completion,
then measure the result with the commands above.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ nav:
- v3 Manual:
- Getting Started: v3/getting-started.md
- Migrating From Older Releases: v3/migrating-from-older-releases.md
- Binary Size: v3/binary-size.md
- Examples:
- Greet: v3/examples/greet.md
- Flags:
Expand Down
Loading