netty/netty — pull request #2038 by danielnorberg (2013-12-05 03:55:29+00:00)
Title: Specialized EMPTY_BUFFER class

This pull request replaces the use of a plain BigEndianHeapChannelBuffer as the EMPTY_BUFFER singleton with a specialized EmptyChannelBuffer class.

EmptyChannelBuffer never writes its indices, which avoids contention when the EMPTY_BUFFER singleton is used concurrently. Although the current EMPTY_BUFFER is effectively immutable, calls like e.g. readBytes(0) causes writes of zero to the readerIndex. This contention was observed on a 12 (physical) core machine. Using the EmptyChannelBuffer class instead eliminated contention and greatly improved throughput.