Skip to content

package-naming: cache std packages listing - #1809

Open
alexandear wants to merge 3 commits into
revive-lint:masterfrom
alexandear:package-naming-cache-std
Open

alexandear wants to merge 3 commits into
revive-lint:masterfrom
alexandear:package-naming-cache-std

Conversation

@alexandear

Copy link
Copy Markdown
Member

package-naming spawned a go list std subprocess on every Configure call when check-collision-with-all-std is enabled. The listing is now loaded once per process and shared by all rule instances, and it only requests package names instead of the full default load mode.

Benchmarks

Measured on macOS machine with only package-naming.check-collision-with-all-std enabled.

End-to-end revive run

Build cache Before After Saved
Warm 0.24s 0.15–0.16s ~0.08s (−35%)
Cold GOCACHE 0.74s 0.29s ~0.45s (−61%)

Source of the saving: load mode

packages.Load of "std" in isolation (381 packages, 5 iterations, warm cache):

Mode First call Steady state
Default 960ms ~205ms
NeedName 139ms ~117ms

The cache pays off only in processes that configure the rule more than once:

  • embedders using revivelib
  • golangci-lint
  • the test suite

`package-naming` spawned a `go list std` subprocess on every `Configure` call
when `check-collision-with-all-std` is enabled. The listing is now loaded once
per process and shared by all rule instances, and it only requests package
names instead of the full default load mode.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Package-level load failures may be cached permanently, and the new test does not verify cache behavior.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Caches standard-library package names to reduce repeated package-naming configuration overhead.

Changes:

  • Adds a process-wide synchronized package-name cache.
  • Uses packages.NeedName to reduce load cost.
  • Adds repeated-configuration coverage.
File Description
rule/​package_naming.go Implements cached standard-library loading.
rule/​package_naming_test.go Adds repeated configuration testing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rule/package_naming.go
Comment thread rule/package_naming_test.go Outdated
`packages.Load` can report per-package failures while returning a nil
top-level error, so a partial standard library listing was cached for the
lifetime of the process. Treat package errors as a load failure instead.

Also configure separate rule instances in the test, so it exercises the
process-wide cache rather than the per-instance early return.
@alexandear
alexandear force-pushed the package-naming-cache-std branch from 74866c7 to 49dac86 Compare September 25, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants