Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: skip debug work when not in debug mode #60

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

- [#59](https://github.com/cosmos/gogoproto/pull/59) Reuse buffers and gzip readers to reduce memory allocations during MergedFileDescriptors.
- [#60](https://github.com/cosmos/gogoproto/pull/60) Skip work to check import path and file descriptor differences during MergedFileDescriptors, when not in debug mode.

## [v1.4.7](https://github.com/cosmos/gogoproto/releases/tag/v1.4.7) - 2023-03-30

Expand Down
19 changes: 12 additions & 7 deletions proto/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ func mergedFileDescriptors(debug bool) (*descriptorpb.FileDescriptorSet, error)
}

// While combing through the file descriptors, we'll also log any errors
// we encounter.
// we encounter -- only if debug is true. Otherwise, we will skip the work
// to check import path or file descriptor differences.
var (
checkImportErr []string
diffErr []string
)

// Add protoregistry file descriptors to our final file descriptor set.
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
fd := protodesc.ToFileDescriptorProto(fileDescriptor)
if err := CheckImportPath(fd.GetName(), fd.GetPackage()); err != nil {
checkImportErr = append(checkImportErr, err.Error())
if debug {
fd := protodesc.ToFileDescriptorProto(fileDescriptor)
if err := CheckImportPath(fd.GetName(), fd.GetPackage()); err != nil {
checkImportErr = append(checkImportErr, err.Error())
}
}

fds.File = append(fds.File, protodesc.ToFileDescriptorProto(fileDescriptor))
Expand Down Expand Up @@ -92,9 +95,11 @@ func mergedFileDescriptors(debug bool) (*descriptorpb.FileDescriptorSet, error)
return nil, err
}

err := CheckImportPath(fd.GetName(), fd.GetPackage())
if err != nil {
checkImportErr = append(checkImportErr, err.Error())
if debug {
err := CheckImportPath(fd.GetName(), fd.GetPackage())
if err != nil {
checkImportErr = append(checkImportErr, err.Error())
}
}

// If it's not in the protoregistry file descriptors, add it.
Expand Down