Reducing code size of protocol buffers

1,901 views
Skip to first unread message

Tim Turner

unread,
Dec 21, 2010, 9:57:50 AM12/21/10
to Protocol Buffers
I'm trying to minimize the code size of the protocol buffers. I've
enabled Lite Runtime, but I'd like to reduce it further. There are
several protocol buffers that I am not using which I would like to
conditionally compile out. Is there a way to do this?

I have been able to remove the protobufs from the code, but it re-
numbers them and this appears to cause some sort of runtime memory
corruption.

Igor Gatis

unread,
Dec 21, 2010, 7:51:41 PM12/21/10
to Tim Turner, Protocol Buffers
Which programming language are you working with? C++ or Java?


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Jason Hsueh

unread,
Dec 21, 2010, 8:39:14 PM12/21/10
to Tim Turner, Protocol Buffers
Have you looked at using the optimize_for CODE_SIZE option rather than the lite runtime? The lite runtime minimizes the size of the core protobuf runtime library, but that means you have to generate a more code for each message. Using CODE_SIZE will make your messages use reflection-based algorithms in the "heavy" protobuf library, rather than generating type-specific code. If you have a large number of messages, this may reduce your binary size more than using the lite runtime.

I'm not sure what you mean by things getting renumbered...are you referring to tag numbers?

Tim Turner

unread,
Dec 22, 2010, 10:58:04 AM12/22/10
to Protocol Buffers
This is C++.

I had not tried optimizing for CODE_SIZE. I understood that CODE_SIZE
was the precursor to and not as compact as LITE_RUNTIME.

Yes, I believe they are tag numbers, the enumeration-style numbering
of each possible response or request.

Kenton Varda

unread,
Dec 22, 2010, 7:51:18 PM12/22/10
to Tim Turner, Protocol Buffers
On Wed, Dec 22, 2010 at 7:58 AM, Tim Turner <tim.t...@garmin.com> wrote:
This is C++.

I had not tried optimizing for CODE_SIZE.  I understood that CODE_SIZE
was the precursor to and not as compact as LITE_RUNTIME.

This is not correct.  As Jason says, the generated code for CODE_SIZE is smaller, but depends on a larger runtime library.  LITE_RUNTIME lets you use a smaller runtime library, but the generated code is large (not quite as large as the default SPEED mode, though).
 
Yes, I believe they are tag numbers, the enumeration-style numbering
of each possible response or request.

I still don't get what you mean here.  How are things being "renumbered"?  The numbers are specified in the .proto file.  They don't change unless you edited them.
Reply all
Reply to author
Forward
0 new messages