cap'n proto vs protobuf on the message size

2,477 views
Skip to first unread message

zhe...@gmail.com

unread,
Jul 24, 2014, 10:27:08 PM7/24/14
to capn...@googlegroups.com
Hi,

I know cap'n proto has no cost on serialization and deserialization, but I suspect that will come with certain cost of the actually size of the message.

Just want to know if there is any benchmark on the message size comparison between cap'n proto and protobuf?

Thanks,

Kenton Varda

unread,
Jul 25, 2014, 6:20:37 PM7/25/14
to zhe...@gmail.com, capnproto
The answer to this question will vary quite a bit depending on the use case. If your message is dominated by large strings, for example, then protobufs and cap'n proto will tend to have the same size. If your message is dominated by 32-bit integer values which usually only hold small numbers, then Protobufs is likely to win due to varint encoding. If you have lots of unset "optional" fields, protobufs is also likely to win since it doesn't encode those. On the other hand, if all your fields are usually set and your integer values tend to use all the bits available to them, then Cap'n Proto may win by virtue of not using any bytes on "tags" (fields are identified purely by their offset).

In general, you are correct that Protobufs will tend to be smaller.

Cap'n Proto also offers an optional compression step called "packing" which is optimized to remove zero-valued bytes. With packing, Cap'n Proto is competitive with Protobufs on size and still generally faster (though no longer infinitely faster).

We have three contrived benchmarks in the Cap'n Proto codebase. Since they are measuring totally made-up cases, it's hard to say how realistic they are, but they come out like so:
- "CarSales" (lots of flat numeric data): Protobuf is 1% larger than Cap'n Proto, or 40% larger than packed Cap'n Proto.
- "CatRank" (string-heavy): Protobuf is 7% smaller than Cap'n Proto, or 1% smaller than packed Cap'n Proto.
- "Eval" (deep object trees with little actual data): Protobuf is 81% smaller than Cap'n Proto, or 39% smaller than packed Cap'n Proto.

-Kenton

--
Sandstorm.io is crowdfunding! http://igg.me/at/sandstorm


--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at http://groups.google.com/group/capnproto.

Reply all
Reply to author
Forward
0 new messages