Skip to content

perf: lazily compute proto registry; ci: fix Go setup and add generate check#435

Merged
wenchy merged 5 commits into
masterfrom
zino.protocompile-upgrade-prep
Jul 10, 2026
Merged

perf: lazily compute proto registry; ci: fix Go setup and add generate check#435
wenchy merged 5 commits into
masterfrom
zino.protocompile-upgrade-prep

Conversation

@Kybxd

@Kybxd Kybxd commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • CI: use go-version-file: go.mod for Go setup — removes the hardcoded/matrix Go version in testing.yml and release.yml, so CI always builds with the exact Go version declared in go.mod instead of a value that can silently drift out of sync.
  • perf: lazily compute proto registry with generated filesProtoRegistryFilesWithGenerated is only needed by a few call paths (PreserveFieldNumbers, preprocess(useGeneratedProtos=true, ...), the exporter's advanced mode). Previously it was eagerly parsed/compiled in every NewGeneratorWithOptions call regardless of whether it was used. This change turns it into a sync.Once-guarded lazy getter, avoiding the extra glob+compile IO/CPU cost on the common path while still computing it once and caching the result when actually needed.
  • CI: bump golangci-lint-action to latest and add a go generate drift check — ensures generated code (e.g. embed.go outputs) is always committed and up to date, catching stale generated files at PR time instead of at review time.
  • CI: fix step ordering in testing.ymlInstall Go (which reads go-version-file: go.mod) was running before Checkout Code, so the repo wasn't checked out yet and go.mod couldn't be found. Reordered so checkout happens first.

Verification

  • go build ./..., go vet ./..., go test ./... all pass.
  • go generate ./... is idempotent (no diff after running).

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJul 9, 2026, 12:52 PM

@Kybxd
Kybxd requested a review from wenchy July 9, 2026 08:28
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.58%. Comparing base (75844f4) to head (79d66e7).

Files with missing lines Patch % Lines
internal/protogen/protogen.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
+ Coverage   75.57%   75.58%   +0.01%     
==========================================
  Files          88       88              
  Lines        9515     9520       +5     
==========================================
+ Hits         7191     7196       +5     
  Misses       1749     1749              
  Partials      575      575              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread internal/protogen/protogen.go Outdated
// result in [Generator.ProtoRegistryFilesWithGenerated]; subsequent calls
// return the cached value. If the field is already set (e.g. by tests),
// it is returned as-is without invoking the parser.
func (gen *Generator) GetProtoRegistryFilesWithGenerated() *protoregistry.Files {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to export this func as public API?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, no need to export it. Renamed to getProtoRegistryFilesWithGenerated (unexported) in 79d66e7.

Comment thread internal/protogen/protogen.go Outdated
Comment on lines +140 to +146
if useGeneratedProtos {
protoRegistryFiles = gen.ProtoRegistryFilesWithGenerated
protoRegistryFiles = gen.GetProtoRegistryFilesWithGenerated()
}
if gen.OutputOpt.PreserveFieldNumbers {
// if preserveFieldNumbers enabled, parse generated protos before they
// are deleted
_ = gen.GetProtoRegistryFilesWithGenerated()

@wenchy wenchy Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. recursive call chain: parseProtoRegistryFiles -> GetProtoRegistryFilesWithGenerated -> parseProtoRegistryFiles
  2. if useGeneratedProtos || gen.OutputOpt.PreserveFieldNumbers then protoRegistryFiles = gen.GetProtoRegistryFilesWithGenerated()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  1. Good catch, that recursive call was a leftover from an earlier version - the current code already calls parseProtoRegistryFiles directly (not through getProtoRegistryFilesWithGenerated), so there's no recursion.
  2. Merged the two ifs into if useGeneratedProtos || gen.OutputOpt.PreserveFieldNumbers { protoRegistryFiles = gen.getProtoRegistryFilesWithGenerated() } as suggested, in 79d66e7.

…implify preprocess condition

Address review comments on PR #435:
- Rename GetProtoRegistryFilesWithGenerated to getProtoRegistryFilesWithGenerated
  since it's only used within the protogen package, no need to export it as
  public API.
- Merge the two separate if-checks in preprocess into a single condition
  (useGeneratedProtos || gen.OutputOpt.PreserveFieldNumbers) that decides
  whether to parse generated protos.
- Simplify the doc comment accordingly.
@Kybxd
Kybxd requested a review from wenchy July 9, 2026 12:51
@wenchy
wenchy merged commit 445fda5 into master Jul 10, 2026
9 checks passed
@wenchy
wenchy deleted the zino.protocompile-upgrade-prep branch July 10, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants