Skip to content

docs: explain lower-allocation logging of netip values - #1604

Open
kanjih wants to merge 1 commit into
uber-go:masterfrom
kanjih:docs/netip-allocation-guidance
Open

kanjih wants to merge 1 commit into
uber-go:masterfrom
kanjih:docs/netip-allocation-guidance

Conversation

@kanjih

@kanjih kanjih commented Oct 15, 2026

Copy link
Copy Markdown

Passing a netip.Addr or netip.AddrPort to Stringer can allocate even when the log level is disabled. Document using Logger.Check followed by String to avoid boxing the address and to skip formatting dropped entries. Include an executable example and benchmarks for both types with logging enabled and disabled.

Related to #1125. This is a documentation workaround using existing APIs, not native netip field support, and intentionally does not close the feature request. Enabled entries still allocate for string formatting and fields.

Allocation results on Go 1.24.2, darwin/arm64 (Apple M1 Pro), consistent across three runs:

Value Logging Stringer Check + String
Addr disabled 88 B, 2 allocs/op 0 B, 0 allocs/op
AddrPort disabled 96 B, 2 allocs/op 0 B, 0 allocs/op
Addr enabled 104 B, 3 allocs/op 80 B, 2 allocs/op
AddrPort enabled 120 B, 3 allocs/op 88 B, 2 allocs/op

Validation:

  • make test: passed across all four modules, with the race detector.
  • go test -run '^ExampleLogger_Check' -bench '^BenchmarkNetipFields$' -benchmem -count=3 .: passed.
  • make tidy-lint license-lint: passed.
  • make golangci-lint: passed across all four modules using golangci-lint v2.14.0 and Go 1.26.9.
  • GOTOOLCHAIN=go1.26.9 make vulncheck: passed.

The initial make lint attempt used a local golangci-lint built with Go 1.24, which could not load the Go 1.25 gRPC test module. The initial vulnerability scan also reported old Go 1.24.2 standard-library vulnerabilities. Both checks passed after selecting the newer tools; repository dependencies were unchanged.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants