netty/netty — pull request #199 by spullara (2012-02-23 22:12:54+00:00)
Title: Optimization work for reading HTTP headers

We currently read HTTP headers by proactively parsing the header block into a linked hashed multi map. This is wasteful on a number of levels. Many objects are created and stored in the map, we double the size of the header block simply by using strings instead of bytes and we have the added overhead of the map itself. Additionally, because of the default buffer size and the way the parser works, we typically do most of this operation twice. This change optimizes the parse step by ensuring that we have a complete header block before allocating anything and then doing a single allocation of a exactly sized buffer along with a list of name and value indexes into the header block. In the case where the headers are then mutated, we fall back to using the original implementation.

I've also added a set of header parsing tests and a small micro benchmark to gauge performance. Aside from the reduction on memory allocation, we also see a small performance improvement for the degenerate case of someone asking for the values of all headers individually.