perf: lazily compute proto registry; ci: fix Go setup and add generate check#435
Merged
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
wenchy
requested changes
Jul 9, 2026
| // 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 { |
Member
There was a problem hiding this comment.
No need to export this func as public API?
Collaborator
Author
There was a problem hiding this comment.
Good point, no need to export it. Renamed to getProtoRegistryFilesWithGenerated (unexported) in 79d66e7.
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() |
Member
There was a problem hiding this comment.
- recursive call chain:
parseProtoRegistryFiles -> GetProtoRegistryFilesWithGenerated -> parseProtoRegistryFiles if useGeneratedProtos || gen.OutputOpt.PreserveFieldNumbersthenprotoRegistryFiles = gen.GetProtoRegistryFilesWithGenerated()
Collaborator
Author
There was a problem hiding this comment.
- Good catch, that recursive call was a leftover from an earlier version - the current code already calls
parseProtoRegistryFilesdirectly (not throughgetProtoRegistryFilesWithGenerated), so there's no recursion. - Merged the two
ifs intoif 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.
wenchy
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
go-version-file: go.modfor Go setup — removes the hardcoded/matrix Go version intesting.ymlandrelease.yml, so CI always builds with the exact Go version declared ingo.modinstead of a value that can silently drift out of sync.ProtoRegistryFilesWithGeneratedis only needed by a few call paths (PreserveFieldNumbers,preprocess(useGeneratedProtos=true, ...), the exporter's advanced mode). Previously it was eagerly parsed/compiled in everyNewGeneratorWithOptionscall regardless of whether it was used. This change turns it into async.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.golangci-lint-actiontolatestand add ago generatedrift check — ensures generated code (e.g.embed.gooutputs) is always committed and up to date, catching stale generated files at PR time instead of at review time.testing.yml—Install Go(which readsgo-version-file: go.mod) was running beforeCheckout Code, so the repo wasn't checked out yet andgo.modcouldn'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).