rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* [PATCH 0/3] support reuse of HeaderHash objects
@ 2009-09-04 21:41 Eric Wong
  2009-09-04 21:41 ` [PATCH 1/3] HeaderHash.new avoids unnecessary object creation Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2009-09-04 21:41 UTC (permalink / raw)
  To: rack-devel


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.

Lighthouse ticket:
  http://rack.lighthouseapp.com/projects/22435-rack/tickets/74

Pull URL:
  git://git.bogomips.org/rack.git

cgit browser:
  http://git.bogomips.org/cgit/rack.git

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(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-01-05 23:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04 21:41 [PATCH 0/3] support reuse of HeaderHash objects Eric Wong
2009-09-04 21:41 ` [PATCH 1/3] HeaderHash.new avoids unnecessary object creation Eric Wong
2009-09-04 21:41 ` [PATCH 2/3] avoid HeaderHash#to_hash in middlewares Eric Wong
2009-09-04 21:41 ` [PATCH 3/3] CommonLogger uses HeaderHash to lookup Content-Length Eric Wong
2009-09-28 10:14 ` [PATCH 4/3] HeaderHash#each yields Lint-OK multivalue headers Eric Wong
2010-01-05 23:58 ` [PATCH 0/3] support reuse of HeaderHash objects Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).