protobuf
protobuf copied to clipboard
Align struct fields for reduced memory overhead
Struct aligning generated protos for optimized memory overhead could have significant savings for any binary manipulating lots of proto messages (grpc servers). I'm not sure if there's other considerations around marshaling/unmarhsaling protos, but wanted to bring up the discussion. Cheers!
https://en.wikipedia.org/wiki/Data_structure_alignment
The generated messages follow the order specified in the .proto files. I don't think the Go generator should re-order them. If there is a benefit to doing so, I argue that it should be done in the .proto files.
gotcha. FYI you can save a measly 16 bytes by swapping the unknownFields and sizeCache, and moving them to the end of the struct instead of the beginning.
Thanks for the suggestion. Swapping unknownFields and sizeCache seems valuable since the latter is always 4B wide. Moving them to the end may or may not help depending on what fields are in between.