You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parser pulls in protodesc/descriptorpb, costing ~3 MB of binary size for a feature most callers don't use #195
Importing github.com/protocolbuffers/txtpbfmt/parser adds about 3.9 MB to a Go binary, of which roughly 3 MB is google.golang.org/protobuf/reflect/protodesc and types/descriptorpb.
The chain is parser → impl → txtpbfmt/descriptor → protodesc + descriptorpb + protoregistry + proto. The only use is in impl.ParseWithMetaCommentConfig:
The guard is a runtime condition, so the linker can't prove it's unreachable and keeps the entire descriptor runtime. Callers who never set SortFieldsByFieldNumber - which I'd guess is most of them, since the flag needs a .desc file on disk - pay the full cost.
Measured with go1.26.0 on linux/amd64, each binary built from a main importing only the package named:
binary
size
hello world
2,405,246
+ txtpbfmt/parser
6,307,225
+ txtpbfmt/parser, with the descriptor import removed from impl
3,237,979
+ protobuf/reflect/protoreflect only
2,563,379
So severing impl → descriptor saves ~3.07 MB. protoreflect itself is only ~158 KB and stays; the expense is entirely protodesc/descriptorpb, which are confined to the 83 lines of descriptor/descriptor.go.
Concretely: CUE uses parser.ParseWithConfig and ast for its textproto support (cuelang.org/go/encoding/protobuf/textproto). Stubbing that out drops the cue binary from 38,747,949 to 35,702,773 bytes — 3.05 MB, 7.9% of the whole tool — and it's all descriptor machinery we never reach.
One shape that would fix it, keeping the CLI feature intact: have config.Config carry an already-resolved protoreflect.MessageDescriptor instead of a ProtoDescriptor file path, and move the file loading into cmd/txtpbfmt. impl already threads protoreflect.MessageDescriptor through parse/parseMessage/parseFieldValue, so it keeps its cheap protoreflect import and loses the expensive ones, and the library stops doing file I/O on the caller's behalf. A registration hook in the descriptor package would also work if you'd rather not change Config.
This is the same shape as #70 — the heavy dependency belongs in the binary that needs it, not in the library. Happy to send a PR if you'd like, once you've picked an approach.
hi, sorry for the problem, thanks for the investigation, I agree with
moving the expensive part to the command binary, I'm happy to review your
PR, once you have it ready I will also need to check if it breaks anything
inside Google.
Activity
mvdan commentedon Sep 9, 2026
cc @stapelberg as you kindly assisted last time on #70 :) I'm not sure who is the best person to route this to.
kssilveira commentedon Sep 10, 2026
mvdan commentedon Sep 11, 2026
@kssilveira thanks very much for the quick response! Here's a small PR: #196
txtpbfmt: move descriptor file loading into the fmt command