Skip to content

Commit 31f5fc9

Browse files
committed
PROTON-19 Optimization for the codec and transport hot paths
Write a cachded encoded value for Accepted states as that does not change and can be easy syntheszied. Also write the descriptor codes directly in the fast path encoders since we know the type and value without needing to dip back into the generic encoder write methods.
1 parent 2951b40 commit 31f5fc9

13 files changed

+102
-54
lines changed

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathAcceptedType.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.Accepted;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.DecodeException;
2726
import org.apache.qpid.proton.codec.Decoder;
2827
import org.apache.qpid.proton.codec.DecoderImpl;
2928
import org.apache.qpid.proton.codec.EncoderImpl;
3029
import org.apache.qpid.proton.codec.EncodingCodes;
30+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3131
import org.apache.qpid.proton.codec.TypeEncoding;
3232
import org.apache.qpid.proton.codec.WritableBuffer;
3333

3434
public class FastPathAcceptedType implements AMQPType<Accepted>, FastPathDescribedTypeConstructor<Accepted> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x24;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000024L), Symbol.valueOf("amqp:accepted:list"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:accepted:list"),
41+
};
42+
43+
private static final byte[] ACCEPTED_ENCODED_BYTES = new byte[] {
44+
EncodingCodes.DESCRIBED_TYPE_INDICATOR,
45+
EncodingCodes.SMALLULONG,
46+
DESCRIPTOR_CODE,
47+
EncodingCodes.LIST0
3948
};
4049

4150
private final AcceptedType acceptedType;
@@ -108,9 +117,7 @@ public void skipValue() {
108117
@Override
109118
public void write(Accepted accepted) {
110119
WritableBuffer buffer = getEncoder().getBuffer();
111-
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
112-
getEncoder().writeUnsignedLong(acceptedType.getDescriptor());
113-
buffer.put(EncodingCodes.LIST0);
120+
buffer.put(ACCEPTED_ENCODED_BYTES, 0, ACCEPTED_ENCODED_BYTES.length);
114121
}
115122

116123
public static void register(Decoder decoder, EncoderImpl encoder) {

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathAmqpSequenceType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.AmqpSequence;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.Decoder;
2726
import org.apache.qpid.proton.codec.DecoderImpl;
2827
import org.apache.qpid.proton.codec.EncoderImpl;
2928
import org.apache.qpid.proton.codec.EncodingCodes;
29+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3030
import org.apache.qpid.proton.codec.TypeEncoding;
3131
import org.apache.qpid.proton.codec.WritableBuffer;
3232

3333
public class FastPathAmqpSequenceType implements AMQPType<AmqpSequence>, FastPathDescribedTypeConstructor<AmqpSequence> {
3434

35+
private static final byte DESCRIPTOR_CODE = 0x76;
36+
3537
private static final Object[] DESCRIPTORS =
3638
{
37-
UnsignedLong.valueOf(0x0000000000000076L), Symbol.valueOf("amqp:amqp-sequence:list"),
39+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:amqp-sequence:list"),
3840
};
3941

4042
private final AmqpSequenceType sequenceType;
@@ -90,7 +92,8 @@ public void skipValue() {
9092
public void write(AmqpSequence sequence) {
9193
WritableBuffer buffer = getEncoder().getBuffer();
9294
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
93-
getEncoder().writeUnsignedLong(sequenceType.getDescriptor());
95+
buffer.put(EncodingCodes.SMALLULONG);
96+
buffer.put(DESCRIPTOR_CODE);
9497
getEncoder().writeObject(sequence.getValue());
9598
}
9699

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathAmqpValueType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.AmqpValue;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.Decoder;
2726
import org.apache.qpid.proton.codec.DecoderImpl;
2827
import org.apache.qpid.proton.codec.EncoderImpl;
2928
import org.apache.qpid.proton.codec.EncodingCodes;
29+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3030
import org.apache.qpid.proton.codec.TypeEncoding;
3131
import org.apache.qpid.proton.codec.WritableBuffer;
3232

3333
public class FastPathAmqpValueType implements AMQPType<AmqpValue>, FastPathDescribedTypeConstructor<AmqpValue> {
3434

35+
private static final byte DESCRIPTOR_CODE = 0x77;
36+
3537
private static final Object[] DESCRIPTORS =
3638
{
37-
UnsignedLong.valueOf(0x0000000000000077L), Symbol.valueOf("amqp:amqp-value:*"),
39+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:amqp-value:*"),
3840
};
3941

4042
private final AmqpValueType valueType;
@@ -90,7 +92,8 @@ public void skipValue() {
9092
public void write(AmqpValue value) {
9193
WritableBuffer buffer = getEncoder().getBuffer();
9294
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
93-
getEncoder().writeUnsignedLong(valueType.getDescriptor());
95+
buffer.put(EncodingCodes.SMALLULONG);
96+
buffer.put(DESCRIPTOR_CODE);
9497
getEncoder().writeObject(value.getValue());
9598
}
9699

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathApplicationPropertiesType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.Decoder;
2726
import org.apache.qpid.proton.codec.DecoderImpl;
2827
import org.apache.qpid.proton.codec.EncoderImpl;
2928
import org.apache.qpid.proton.codec.EncodingCodes;
29+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3030
import org.apache.qpid.proton.codec.MapType;
3131
import org.apache.qpid.proton.codec.TypeEncoding;
3232
import org.apache.qpid.proton.codec.WritableBuffer;
3333

3434
public class FastPathApplicationPropertiesType implements AMQPType<ApplicationProperties>, FastPathDescribedTypeConstructor<ApplicationProperties> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x74;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000074L), Symbol.valueOf("amqp:application-properties:map"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:application-properties:map"),
3941
};
4042

4143
private final ApplicationPropertiesType propertiesType;
@@ -92,7 +94,8 @@ public void write(ApplicationProperties val) {
9294
WritableBuffer buffer = getEncoder().getBuffer();
9395

9496
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
95-
getEncoder().writeUnsignedLong(propertiesType.getDescriptor());
97+
buffer.put(EncodingCodes.SMALLULONG);
98+
buffer.put(DESCRIPTOR_CODE);
9699

97100
MapType mapType = (MapType) getEncoder().getType(val.getValue());
98101

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDataType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.Data;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.Decoder;
2726
import org.apache.qpid.proton.codec.DecoderImpl;
2827
import org.apache.qpid.proton.codec.EncoderImpl;
2928
import org.apache.qpid.proton.codec.EncodingCodes;
29+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3030
import org.apache.qpid.proton.codec.TypeEncoding;
3131
import org.apache.qpid.proton.codec.WritableBuffer;
3232

3333
public class FastPathDataType implements AMQPType<Data>, FastPathDescribedTypeConstructor<Data> {
3434

35+
private static final byte DESCRIPTOR_CODE = 0x75;
36+
3537
private static final Object[] DESCRIPTORS =
3638
{
37-
UnsignedLong.valueOf(0x0000000000000075L), Symbol.valueOf("amqp:data:binary"),
39+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:data:binary"),
3840
};
3941

4042
private final DataType dataType;
@@ -90,7 +92,8 @@ public void skipValue() {
9092
public void write(Data data) {
9193
WritableBuffer buffer = getEncoder().getBuffer();
9294
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
93-
getEncoder().writeUnsignedLong(dataType.getDescriptor());
95+
buffer.put(EncodingCodes.SMALLULONG);
96+
buffer.put(DESCRIPTOR_CODE);
9497
getEncoder().writeBinary(data.getValue());
9598
}
9699

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDeliveryAnnotationsType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333

3434
public class FastPathDeliveryAnnotationsType implements AMQPType<DeliveryAnnotations>, FastPathDescribedTypeConstructor<DeliveryAnnotations> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x71;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000071L), Symbol.valueOf("amqp:delivery-annotations:map"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:delivery-annotations:map"),
3941
};
4042

4143
private final DeliveryAnnotationsType annotationsType;
@@ -93,7 +95,8 @@ public void write(DeliveryAnnotations val) {
9395
WritableBuffer buffer = getEncoder().getBuffer();
9496

9597
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
96-
getEncoder().writeUnsignedLong(annotationsType.getDescriptor());
98+
buffer.put(EncodingCodes.SMALLULONG);
99+
buffer.put(DESCRIPTOR_CODE);
97100

98101
MapType mapType = (MapType) getEncoder().getType(val.getValue());
99102

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathFooterType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333

3434
public class FastPathFooterType implements AMQPType<Footer>, FastPathDescribedTypeConstructor<Footer> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x78;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000078L), Symbol.valueOf("amqp:footer:map"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:footer:map"),
3941
};
4042

4143
private final FooterType footerType;
@@ -92,7 +94,8 @@ public void write(Footer val) {
9294
WritableBuffer buffer = getEncoder().getBuffer();
9395

9496
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
95-
getEncoder().writeUnsignedLong(footerType.getDescriptor());
97+
buffer.put(EncodingCodes.SMALLULONG);
98+
buffer.put(DESCRIPTOR_CODE);
9699

97100
MapType mapType = (MapType) getEncoder().getType(val.getValue());
98101

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathHeaderType.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.Header;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.DecodeException;
2726
import org.apache.qpid.proton.codec.Decoder;
2827
import org.apache.qpid.proton.codec.DecoderImpl;
2928
import org.apache.qpid.proton.codec.EncoderImpl;
3029
import org.apache.qpid.proton.codec.EncodingCodes;
30+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3131
import org.apache.qpid.proton.codec.TypeEncoding;
3232
import org.apache.qpid.proton.codec.WritableBuffer;
3333

3434
public class FastPathHeaderType implements AMQPType<Header>, FastPathDescribedTypeConstructor<Header> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x70;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000070L), Symbol.valueOf("amqp:header:list"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:header:list"),
3941
};
4042

4143
private final HeaderType headerType;
@@ -140,22 +142,21 @@ public void write(Header value) {
140142
byte encodingCode = deduceEncodingCode(value, count);
141143

142144
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
143-
getEncoder().writeUnsignedLong(headerType.getDescriptor());
145+
buffer.put(EncodingCodes.SMALLULONG);
146+
buffer.put(DESCRIPTOR_CODE);
147+
buffer.put(encodingCode);
144148

145149
// Optimized step, no other data to be written.
146-
if (count == 0 || encodingCode == EncodingCodes.LIST0) {
147-
buffer.put(EncodingCodes.LIST0);
150+
if (encodingCode == EncodingCodes.LIST0) {
148151
return;
149152
}
150153

151154
final int fieldWidth;
152155

153156
if (encodingCode == EncodingCodes.LIST8) {
154157
fieldWidth = 1;
155-
buffer.put(EncodingCodes.LIST8);
156158
} else {
157159
fieldWidth = 4;
158-
buffer.put(EncodingCodes.LIST32);
159160
}
160161

161162
int startIndex = buffer.position();

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathMessageAnnotationsType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.Decoder;
2726
import org.apache.qpid.proton.codec.DecoderImpl;
2827
import org.apache.qpid.proton.codec.EncoderImpl;
2928
import org.apache.qpid.proton.codec.EncodingCodes;
29+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3030
import org.apache.qpid.proton.codec.MapType;
3131
import org.apache.qpid.proton.codec.TypeEncoding;
3232
import org.apache.qpid.proton.codec.WritableBuffer;
3333

3434
public class FastPathMessageAnnotationsType implements AMQPType<MessageAnnotations>, FastPathDescribedTypeConstructor<MessageAnnotations> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x72;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000072L), Symbol.valueOf("amqp:message-annotations:map"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:message-annotations:map"),
3941
};
4042

4143
private final MessageAnnotationsType annotationsType;
@@ -93,7 +95,8 @@ public void write(MessageAnnotations val) {
9395
WritableBuffer buffer = getEncoder().getBuffer();
9496

9597
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
96-
getEncoder().writeUnsignedLong(annotationsType.getDescriptor());
98+
buffer.put(EncodingCodes.SMALLULONG);
99+
buffer.put(DESCRIPTOR_CODE);
97100

98101
MapType mapType = (MapType) getEncoder().getType(val.getValue());
99102

proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathPropertiesType.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
import org.apache.qpid.proton.amqp.UnsignedLong;
2323
import org.apache.qpid.proton.amqp.messaging.Properties;
2424
import org.apache.qpid.proton.codec.AMQPType;
25-
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
2625
import org.apache.qpid.proton.codec.DecodeException;
2726
import org.apache.qpid.proton.codec.Decoder;
2827
import org.apache.qpid.proton.codec.DecoderImpl;
2928
import org.apache.qpid.proton.codec.EncoderImpl;
3029
import org.apache.qpid.proton.codec.EncodingCodes;
30+
import org.apache.qpid.proton.codec.FastPathDescribedTypeConstructor;
3131
import org.apache.qpid.proton.codec.TypeEncoding;
3232
import org.apache.qpid.proton.codec.WritableBuffer;
3333

3434
public class FastPathPropertiesType implements AMQPType<Properties>, FastPathDescribedTypeConstructor<Properties> {
3535

36+
private static final byte DESCRIPTOR_CODE = 0x73;
37+
3638
private static final Object[] DESCRIPTORS =
3739
{
38-
UnsignedLong.valueOf(0x0000000000000073L), Symbol.valueOf("amqp:properties:list"),
40+
UnsignedLong.valueOf(DESCRIPTOR_CODE), Symbol.valueOf("amqp:properties:list"),
3941
};
4042

4143
private final PropertiesType propertiesType;
@@ -164,22 +166,21 @@ public void write(Properties value) {
164166
byte encodingCode = deduceEncodingCode(value, count);
165167

166168
buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
167-
getEncoder().writeUnsignedLong(propertiesType.getDescriptor());
169+
buffer.put(EncodingCodes.SMALLULONG);
170+
buffer.put(DESCRIPTOR_CODE);
171+
buffer.put(encodingCode);
168172

169173
// Optimized step, no other data to be written.
170-
if (count == 0 || encodingCode == EncodingCodes.LIST0) {
171-
buffer.put(EncodingCodes.LIST0);
174+
if (encodingCode == EncodingCodes.LIST0) {
172175
return;
173176
}
174177

175178
final int fieldWidth;
176179

177180
if (encodingCode == EncodingCodes.LIST8) {
178181
fieldWidth = 1;
179-
buffer.put(EncodingCodes.LIST8);
180182
} else {
181183
fieldWidth = 4;
182-
buffer.put(EncodingCodes.LIST32);
183184
}
184185

185186
int startIndex = buffer.position();

0 commit comments

Comments
 (0)