#74 ✓resolved
ericwong

[PATCH 0/3] support reuse of HeaderHash objects

Reported by ericwong | September 4th, 2009 @ 09:35 PM | in 1.1

HeaderHash objects are needlessly created and discarded by various
pieces of Rack middleware, leading to unnecessary overhead
from both object creation + GC and iteration overhead via
headers#each.

Enable and promote the reuse of them by making HeaderHash.new
idempotent iff a HeaderHash object is passed to the class method.

These changes resulted in a 20-25% increase in performance
with the following simple config.ru:

------------- config.ru --------------- use Rack::ContentLength
use Rack::Deflater
use Rack::ContentType
use Rack::ShowExceptions
run Rack::Lobster.new
---------------- 8< -------------------

Responses with more headers (especially those with multiple Set-Cookie
headers) are expected to benefit even more. This adds a small amount of
overhead in that it adds a conditional to HeaderHash.new, so
applications that only use HeaderHash.new once in the entire request
cycle will suffer slightly. However, the majority of applications
should benefit if they use more than one middleware.

Independent benchmarks on real applications are very much encouraged,
thanks.

Eric Wong (3):

  HeaderHash.new avoids unnecessary object creation
  avoid HeaderHash#to_hash in middlewares
  CommonLogger uses HeaderHash to lookup Content-Length

lib/rack/chunked.rb | 4 ++-- lib/rack/commonlogger.rb | 9 +++------ lib/rack/content_type.rb | 2 +- lib/rack/response.rb | 4 ++-- lib/rack/utils.rb | 4 ++++ test/spec_rack_utils.rb | 8 ++++++++ 6 files changed, 20 insertions(+), 11 deletions(-)

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Pages