Use 1000 as default value for the max composite buffer components. This safe a lot of byte copies and so speed up every decoder that extends FrameDecoder. See #435

This commit is contained in:
norman 2012-07-03 08:32:06 +02:00
parent bf23828734
commit 91d5c9a0a6
5 changed files with 6 additions and 7 deletions

View File

@ -179,11 +179,13 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
*/ */
public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler { public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler {
public static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS = 1000;
private boolean unfold; private boolean unfold;
protected ChannelBuffer cumulation; protected ChannelBuffer cumulation;
private volatile ChannelHandlerContext ctx; private volatile ChannelHandlerContext ctx;
private int copyThreshold; private int copyThreshold;
private int maxCumulationBufferComponents = 4; private int maxCumulationBufferComponents = DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS;
protected FrameDecoder() { protected FrameDecoder() {
this(false); this(false);
@ -252,7 +254,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
* Returns the maximum number of components in the cumulation buffer. If the number of * Returns the maximum number of components in the cumulation buffer. If the number of
* the components in the cumulation buffer exceeds this value, the components of the * the components in the cumulation buffer exceeds this value, the components of the
* cumulation buffer are consolidated into a single component, involving memory copies. * cumulation buffer are consolidated into a single component, involving memory copies.
* The default value of this property is {@code 4}. * The default value of this property {@link #DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS}.
*/ */
public final int getMaxCumulationBufferComponents() { public final int getMaxCumulationBufferComponents() {
return maxCumulationBufferComponents; return maxCumulationBufferComponents;
@ -262,7 +264,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
* Sets the maximum number of components in the cumulation buffer. If the number of * Sets the maximum number of components in the cumulation buffer. If the number of
* the components in the cumulation buffer exceeds this value, the components of the * the components in the cumulation buffer exceeds this value, the components of the
* cumulation buffer are consolidated into a single component, involving memory copies. * cumulation buffer are consolidated into a single component, involving memory copies.
* The default value of this property is {@code 4} and its minimum allowed value is {@code 2}. * The default value of this property is {@link #DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS}
* and its minimum allowed value is {@code 2}.
*/ */
public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents) { public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents) {
if (maxCumulationBufferComponents < 2) { if (maxCumulationBufferComponents < 2) {

View File

@ -55,7 +55,6 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder<VoidEnum> {
public CompatibleMarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) { public CompatibleMarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) {
this.provider = provider; this.provider = provider;
this.maxObjectSize = maxObjectSize; this.maxObjectSize = maxObjectSize;
setMaxCumulationBufferComponents(Integer.MAX_VALUE);
} }
@Override @Override

View File

@ -57,7 +57,6 @@ public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
public MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) { public MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) {
super(maxObjectSize, 0, 4, 0, 4); super(maxObjectSize, 0, 4, 0, 4);
this.provider = provider; this.provider = provider;
setMaxCumulationBufferComponents(Integer.MAX_VALUE);
} }

View File

@ -61,7 +61,6 @@ public class CompatibleObjectDecoder extends ReplayingDecoder<CompatibleObjectDe
*/ */
public CompatibleObjectDecoder() { public CompatibleObjectDecoder() {
super(CompatibleObjectDecoderState.READ_HEADER); super(CompatibleObjectDecoderState.READ_HEADER);
setMaxCumulationBufferComponents(Integer.MAX_VALUE);
} }
/** /**

View File

@ -93,7 +93,6 @@ public class ObjectDecoder extends LengthFieldBasedFrameDecoder {
public ObjectDecoder(int maxObjectSize, ClassResolver classResolver) { public ObjectDecoder(int maxObjectSize, ClassResolver classResolver) {
super(maxObjectSize, 0, 4, 0, 4); super(maxObjectSize, 0, 4, 0, 4);
this.classResolver = classResolver; this.classResolver = classResolver;
setMaxCumulationBufferComponents(Integer.MAX_VALUE);
} }