From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs150223fgw; Fri, 4 Sep 2009 14:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.141.19.21 as permitted sender) client-ip=10.141.19.21; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.141.19.21 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.141.19.21]) by 10.141.19.21 with SMTP id w21mr9631449rvi.16.1252100532478 (num_hops = 1); Fri, 04 Sep 2009 14:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:from:to:subject :date:message-id:x-mailer:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=6wPDUOE6yy0c1FX3dYJzXlOzoPt7tYY1ZQhjvHptndc=; b=Aaqbdga3NheCeOk6ZsAnzdff6yyhi8ZES1H4Anz2n5isKYmkU4GCnIGad+xtPYJl5K olTp+PCwTrmZfA5BLNnb4/Ah/W1DaxblVsWFtuKHiBecDklfIm+kT5pvQN+7asGXXLDn 7VAnBI9VF/CoG6syCdr/KR1uh7WvC91en7/8Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:from :to:subject:date:message-id:x-mailer:reply-to:sender:precedence :x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=figx4j/CLFWLZvvDavZipFpzZPPs0XUz+Jq9CDvVF82KogyxQe1ZTXzBWU33eeyxrZ k+zLZxcoN2dUtU/EMKSqfcUrcvm+thIFgs8AL1uy1RNEdZYLFVXdQjswnXrPB5MPlPRJ qj4YCUI/0/Ai26Zw1vkFfjx+iPfB0PeN+2SIY= Received: by 10.141.19.21 with SMTP id w21mr1762409rvi.16.1252100532423; Fri, 04 Sep 2009 14:42:12 -0700 (PDT) Received: by 10.106.33.9 with SMTP id g9gr1639prg.0; Fri, 04 Sep 2009 14:42:01 -0700 (PDT) X-Sender: normalperson@yhbt.net X-Apparently-To: rack-devel@googlegroups.com Received: by 10.141.15.11 with SMTP id s11mr3415537rvi.27.1252100520273; Fri, 04 Sep 2009 14:42:00 -0700 (PDT) Received: by 10.141.15.11 with SMTP id s11mr3415536rvi.27.1252100520250; Fri, 04 Sep 2009 14:42:00 -0700 (PDT) Return-Path: Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by gmr-mx.google.com with ESMTP id 25si338764pzk.7.2009.09.04.14.42.00; Fri, 04 Sep 2009 14:42:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) smtp.mail=normalperson@yhbt.net Received: from localhost (unknown [12.186.229.34]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id AD0C11F509 for ; Fri, 4 Sep 2009 21:41:59 +0000 (UTC) From: Eric Wong To: rack-devel@googlegroups.com Subject: [PATCH 0/3] support reuse of HeaderHash objects Date: Fri, 4 Sep 2009 14:41:51 -0700 Message-Id: <1252100514-2748-1-git-send-email-normalperson@yhbt.net> X-Mailer: git-send-email 1.6.4.2.236.gf324c Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com 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(-)