Alex Antonov wrote:
When I use .writeTo(...) and pass it a CompressionOutputStream as an
input, it takes only 38,226,661 ns to compress 112,178 bytes.

Wow! Glad to hear this helped so much.

If you have a sequence of messages, you could try using a single CodedOutputStream. Something like:

CodedOutputStream out = new CodedOutputStream(compressionStream);
for (msg : messages) {

This should be slightly faster than using:


because it avoids re-allocating the CodedOutputStream (and its internal buffer). It should be quite a bit better for small messages.

Now I'm trying to figure out how I can speed up the decompression on
the receiving side.

What I have right now is:
  * Take the CompressionInputStream, convert it into a byte[]
  * Take the resulting byte[] and do .parseFrom(byte[])

This seems to be a faster route, then just
doing .parseFrom(CompressionInputStream).

Interesting. The only reason that I can think of which might make the byte[] version faster is that maybe you use a big read, while .parseFrom(InputStream) defaults to 4096 bytes. You could try editing the source to make BUFFER_SIZE in CodedInputStream bigger, if you care.

The only thing I can think of is if you are reading a sequence of many messages, you can again re-use a single CodedInputStream, although this requires some work. Again, this will be better for small messages but probably not large messages. This is trickier than re-using a single CodedOutputStream. If you are interested, I can send the details about what I have used. Although to be honest: I haven't tested it carefully to see if this is *actually* faster than doing the simple thing such as .parseFrom() and friends.


Evan Jones

You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to