Skip to content

Commit

Permalink
perf: skip debug work when not in debug mode (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff authored Apr 13, 2023
1 parent 7dca9a2 commit d932639
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
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

0 comments on commit d932639

Please sign in to comment.