Improving performance of ProtobufDecoder
IanS
iswett at yahoo.com
Thu Jul 15 16:41:44 EDT 2010
I believe most of the difference is that CodedInputStream allocates a 4096
byte buffer every time, which can start becoming a lot of overhead for many
small messages. I tried this based on a forum post I can't seem to locate
right now.
Thanks for the suggestion about array, I changed the method to a more
'zero-copy' approach now:
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object
msg) throws Exception {
if (!(msg instanceof ChannelBuffer)) {
return msg;
}
ChannelBuffer buf = (ChannelBuffer) msg;
if(buf.hasArray()) {
if(extensionRegistry == null) {
return prototype.newBuilderForType().mergeFrom(buf.array(),
buf.arrayOffset(), buf.readableBytes()).build();
}
else {
return prototype.newBuilderForType().mergeFrom(buf.array(),
buf.arrayOffset(), buf.readableBytes(), extensionRegistry).build();
}
}
else
{
if (extensionRegistry == null) {
return prototype.newBuilderForType().mergeFrom(
new ChannelBufferInputStream((ChannelBuffer) msg)).build();
} else {
return prototype.newBuilderForType().mergeFrom(
new ChannelBufferInputStream((ChannelBuffer) msg),
extensionRegistry).build();
}
}
}
--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Improving-performance-of-ProtobufDecoder-tp5293790p5299238.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list