Wire protocol buffers vs Cap'n proto - which one is better?

3.1k views Asked by At

I'm currently using wire protocol buffers in one of my android apps and looks like it's parseFrom() method is not very efficient as it takes ~10 ms even to parse a very small amount of data.

So I came across this: https://capnproto.org/index.html

Does anyone know what's the key difference between these two protocol buffers, mainly in terms of performance and features?

2

There are 2 answers

0
pree On BEST ANSWER

For me the issue was creating the Wire instance every time I parse a message.

// Sample code 
Wire wireObj = new Wire(<extension>);
output = wireObj.parseFrom(<buffer>, <extension>);

It turns out that if you create a Wire instance every time you need to parse a message, then it is time consuming. However, if you create it only once and reuse it for all other parsing requests, then it takes very less time (< 1ms).

EDIT:

Note: It still takes slightly longer to parse very first request though.

3
Kenton Varda On

"Wire Protocol Buffers" is just another implementation of Protocol Buffers. Cap'n Proto is an entirely different, incompatible format. The Cap'n Proto web site has lots of text explaining how it is different from Protocol Buffers. The main problem with Cap'n Proto is that it isn't as mature or widely-used.

If you find that a protobuf parser takes 10ms to parse a small amount of data, it's very likely that there is something else wrong. Typically it should be able to parse around a megabyte or more in that time.