1

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
pree
  • 2,297
  • 6
  • 37
  • 55

2 Answers2

4

"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.

Kenton Varda
  • 41,353
  • 8
  • 121
  • 105
  • Makes sense. I checked a few things and looks like the protobuf message parsing with extension data is probably taking more time to parse than the one which doesn't have extension data in it. I might be wrong but this is the behavior I have observed so far. – pree Jun 16 '15 at 18:35
  • 1
    Extensions do take more CPU due to the added abstraction, though on a per-extension basis. That is, if you have a single extension sub-message with tons of data in it, that should be fine; if you have tons of separate extensions, then it's going to be very slow, yes. – Kenton Varda Jun 17 '15 at 17:37
  • That's really useful to know. Your responses pointed me to the right direction and I was able to figure out the issue. I did more investigation and have posted the answer below. – pree Jun 18 '15 at 16:19
0

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.

pree
  • 2,297
  • 6
  • 37
  • 55