In my last test Thrift and Protocol Buffers performance in Java, Some comments told me that there are some tuning parameter for Protocol Buffer which can improve performance magically. The parameter was not turn on by default. I added
option optimize_for = SPEED
to the proto file, and re-generated the Java class, and the result:
Thrift Loop : 10,000,000 Get object : 14,394msec Serdes thrift : 37,671msec Objs per second: 265,456 Total bytes : 1,130,000,000 ProtoBuf Loop : 10,000,000 Get object : 8,170msec Serdes protobuf: 33,054msec Objs per second: 302,535 Total bytes : 829,997,866
From the result, Protocol Buffers is 1.1 times faster than Thrift!
And from the Google Protocol Buffers group, why the optimize for speed was not turn on by default.
When using C++ or Java protocol buffers, for best performance you need to add a line to your .proto files:
option optimize_for = SPEED;
Otherwise, by default, the compiler optimizes for code size. Optimizing for code size results in generated code that around a half to a third of the size, but runs an order of magnitude slower…
Here is the original post