netty/netty — pull request #2707 by idelpivnitskiy (2014-07-26 14:54:01+00:00)
Title: Improve Bzip2BitReader/Writer

Motivation:

Before this changes `Bzip2BitReader` and `Bzip2BitWriter` accessed to a `ByteBuf` byte by byte. So tests for Bzip2 compression codec takes a lot of time if we ran them with paranoid level of resource leak detection. For more information see comments to #2681 and #2689.

Modifications:

- Increased size of bit buffers from 8 to 64 bits.
- Improved reading and writing operations.
- Save link to the incoming `ByteBuf` inside `Bzip2BitReader`.
- Added methods to check possible readable bits and bytes in `Bzip2BitReader`.
- Updated Bzip2 classes to use new API of `Bzip2BitReader`.
- Added new constants to `Bzip2Constants`.

Result:

Increased size of bit buffers and improved performance of Bzip2 compression codec (for general work by 13% and for tests with paranoid level of resource leak detection by 55%).

Results of benchmark to encode and decode an array of 900256 bytes (like in Bzip2 tests):

| normal mode | leakDetectionLevel=paranoid
:--:|:----------------:|:-------------------------------------:
before | 208 ms | 50 s
after | 182 ms | 22 s