tmm1/http_parser.rb — pull request #14 by headius (2012-02-21 12:17:56+00:00)
Title: Perf optimizations for JRuby ext.

* Use RubyString.cat(byte[]) rather than concat(newString(new String(data)))
* Use byte[] instead of String for current header
* Pre-allocate control symbols and compare directly
* Initialize empty strings with 10 byte buffer
* Use respondsTo() instead of respond_to_p
* Wrap incoming content directly rather than making a copy

More could be done; the changes above largely reduce allocation
rates, and remaining allocations are heavy in byte[] and ByteList.
The fetchData method in particular is creating many throwaway byte[]
that could potentially be copied directly from the ByteBuffer into
a target string.

Numbers are improved nicely with this set of fixes, though.

Before (modified bench/thin.rb to skip thin and loop):

Rehearsal ------------------------------------------------
http-parser: 1.635000 0.000000 1.635000 ( 1.635000)
--------------------------------------- total: 1.635000sec

user system total real
http-parser: 0.702000 0.000000 0.702000 ( 0.702000)
Rehearsal ------------------------------------------------
http-parser: 0.662000 0.000000 0.662000 ( 0.661000)
--------------------------------------- total: 0.662000sec

user system total real
http-parser: 0.659000 0.000000 0.659000 ( 0.659000)

After:

Rehearsal ------------------------------------------------
http-parser: 1.395000 0.000000 1.395000 ( 1.395000)
--------------------------------------- total: 1.395000sec

user system total real
http-parser: 0.552000 0.000000 0.552000 ( 0.552000)
Rehearsal ------------------------------------------------
http-parser: 0.509000 0.000000 0.509000 ( 0.510000)
--------------------------------------- total: 0.509000sec

user system total real
http-parser: 0.511000 0.000000 0.511000 ( 0.511000)