Discussion:
[protobuf] Protobuf Binary Size
Roy Barda
2018-12-03 06:33:58 UTC
Permalink
Hi,

I have build protobuf on my Ubuntu environment and saw that the libraries
size are extremely big.

28 MB for libprotobuf.
4 MB for libprotobuf-lite

I'm aware of nanopb project but I need to use gRPC with protobuf and there
is no good, working and maintained solution for nanopb.

I followed the regular build process when I built protobuf (with no special
configuration)

Is there any way to reduce the protobuf library footprint? We are looking
for a 1MB solution.

Thanks,

Roy.
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
'Adam Cozzette' via Protocol Buffers
2018-12-04 03:51:41 UTC
Permalink
Do you plan to link statically or dynamically against the protobuf library?
If you can link against it statically, I think you may find that the linker
is able to remove a lot of unused code. For Android (which is an
environment where we care a lot about code size), what we generally do is:
- Use lite protos only (i.e. set option optimize_for = LITE_RUNTIME in
every .proto file)
- Link against libprotobuf-lite and not libprotobuf
- Pass -ffunction-sections and -fdata-sections to the compiler and
-Wl,-gc-sections to the linker to maximize the linker's ability to strip
out unused code
Post by Roy Barda
Hi,
I have build protobuf on my Ubuntu environment and saw that the libraries
size are extremely big.
28 MB for libprotobuf.
4 MB for libprotobuf-lite
I'm aware of nanopb project but I need to use gRPC with protobuf and there
is no good, working and maintained solution for nanopb.
I followed the regular build process when I built protobuf (with no
special configuration)
Is there any way to reduce the protobuf library footprint? We are looking
for a 1MB solution.
Thanks,
Roy.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Roy Barda
2018-12-04 07:05:04 UTC
Permalink
Thank you Adam for the detailed suggestion.

1. Can you please let me know what was the addition in KB/MB of protobuf
usage when you linked it statically to your Android code?
2. Using libprotobuf-lite blocks me from using the "stream" modifier
(streaming feature) in gRPC, anyway to work around it?

Appreciate your help,
Roy.
Post by 'Adam Cozzette' via Protocol Buffers
Do you plan to link statically or dynamically against the protobuf
library? If you can link against it statically, I think you may find that
the linker is able to remove a lot of unused code. For Android (which is an
- Use lite protos only (i.e. set option optimize_for = LITE_RUNTIME in
every .proto file)
- Link against libprotobuf-lite and not libprotobuf
- Pass -ffunction-sections and -fdata-sections to the compiler and
-Wl,-gc-sections to the linker to maximize the linker's ability to strip
out unused code
Post by Roy Barda
Hi,
I have build protobuf on my Ubuntu environment and saw that the libraries
size are extremely big.
28 MB for libprotobuf.
4 MB for libprotobuf-lite
I'm aware of nanopb project but I need to use gRPC with protobuf and
there is no good, working and maintained solution for nanopb.
I followed the regular build process when I built protobuf (with no
special configuration)
Is there any way to reduce the protobuf library footprint? We are looking
for a 1MB solution.
Thanks,
Roy.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
'Adam Cozzette' via Protocol Buffers
2018-12-04 17:19:08 UTC
Permalink
For one Android binary I worked on recently, the protobuf runtime used
about 135 KB of space. This was for an ARM build, and I imagine the amount
could vary quite a bit depending on the platform and what runtime code you
end up depending on.

I'm not familiar with that gRPC issue, so you may want to ask the gRPC
folks about that. Does the "stream" modifier prevent you from
setting optimize_for = LITE_RUNTIME in the .proto file?
Post by Roy Barda
Thank you Adam for the detailed suggestion.
1. Can you please let me know what was the addition in KB/MB of protobuf
usage when you linked it statically to your Android code?
2. Using libprotobuf-lite blocks me from using the "stream" modifier
(streaming feature) in gRPC, anyway to work around it?
Appreciate your help,
Roy.
Post by 'Adam Cozzette' via Protocol Buffers
Do you plan to link statically or dynamically against the protobuf
library? If you can link against it statically, I think you may find that
the linker is able to remove a lot of unused code. For Android (which is an
- Use lite protos only (i.e. set option optimize_for = LITE_RUNTIME in
every .proto file)
- Link against libprotobuf-lite and not libprotobuf
- Pass -ffunction-sections and -fdata-sections to the compiler and
-Wl,-gc-sections to the linker to maximize the linker's ability to strip
out unused code
Post by Roy Barda
Hi,
I have build protobuf on my Ubuntu environment and saw that the
libraries size are extremely big.
28 MB for libprotobuf.
4 MB for libprotobuf-lite
I'm aware of nanopb project but I need to use gRPC with protobuf and
there is no good, working and maintained solution for nanopb.
I followed the regular build process when I built protobuf (with no
special configuration)
Is there any way to reduce the protobuf library footprint? We are
looking for a 1MB solution.
Thanks,
Roy.
--
You received this message because you are subscribed to the Google
Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Loading...