[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
-
ericwong September 4th, 2009 @ 09:36 PM
- no changes were found...
-
ericwong September 4th, 2009 @ 09:37 PM
- no changes were found...
-
ericwong September 4th, 2009 @ 09:38 PM
Also pushed out to:
git://git.bogomips.org/rack.git
And browsable from:
http://git.bogomips.org/cgit/rack.git (refs/heads/master)
-
Ryan Tomayko September 5th, 2009 @ 12:19 AM
+1 I remember thinking we'd need to do something about this when the HeaderHash changes initially went in.
-
ericwong September 28th, 2009 @ 10:06 AM
Oops, passing HeaderHash in responses would cause breakage with
multi-value headers since they're kept internally as Arrays when servers
are only required to handle strings, this should fix it. -
josh December 11th, 2009 @ 03:14 AM
- Assigned user set to josh
- State changed from new to open
- Milestone set to 1.1
-
josh December 11th, 2009 @ 03:35 AM
- State changed from open to resolved
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป