netty/netty — pull request #3102 by idelpivnitskiy (2014-11-04 18:25:37+00:00)
Title: Rewrite HttpObjectDecoder to make use of proper state machine

Motivation:

HttpObjectDecoder extended ReplayDecoder which is slightly slower then ByteToMessageDecoder. See issue #1498 for more information.

Modifications:

- Changed super class of HttpObjectDecoder from ReplayDecoder to ByteToMessageDecoder.
- Rewrote decode() method of HttpObjectDecoder to use proper state machine.
- Changed private methods HeaderParser.parse(ByteBuf), readHeaders(ByteBuf) and readTrailingHeaders(ByteBuf), skipControlCharacters(ByteBuf) to consider available bytes.
- Set HeaderParser and LineParser as static inner classes.
- Replaced not safe actualReadableBytes() with buffer.readableBytes().

Result:

Improved performance of HttpObjectDecoder by approximately 177%.

Before:
```
Benchmark Mode Samples Score Score error Units
testDecodeWholeRequestInMultipleStepsCRLFDelimiters thrpt 20 5758.466 116.815 ops/s
testDecodeWholeRequestInMultipleStepsLFDelimiters thrpt 20 5997.320 59.245 ops/s
testDecodeWholeRequestInMultipleStepsMixedDelimiters thrpt 20 5794.637 126.579 ops/s
```
After:
```
Benchmark Mode Samples Score Score error Units
testDecodeWholeRequestInMultipleStepsCRLFDelimiters thrpt 20 10164.381 122.096 ops/s
testDecodeWholeRequestInMultipleStepsLFDelimiters thrpt 20 10292.826 123.720 ops/s
testDecodeWholeRequestInMultipleStepsMixedDelimiters thrpt 20 10154.367 123.237 ops/s
```

@normanmaurer @trustin please, check my [benchmark](https://gist.github.com/idelpivnitskiy/2c64cdd20df848ba103f).