From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.25.37.80 with SMTP id l77csp38376lfl; Sun, 5 Oct 2014 01:15:28 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBD4PTDWJVIEBBHX4YOQQKGQEC5TZW4A@googlegroups.com designates 10.50.154.66 as permitted sender) client-ip=10.50.154.66 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBD4PTDWJVIEBBHX4YOQQKGQEC5TZW4A@googlegroups.com designates 10.50.154.66 as permitted sender) smtp.mail=rack-devel+bncBD4PTDWJVIEBBHX4YOQQKGQEC5TZW4A@googlegroups.com; dkim=pass header.i=@googlegroups.com X-Received: from mr.google.com ([10.50.154.66]) by 10.50.154.66 with SMTP id vm2mr745170igb.5.1412496928132 (num_hops = 1); Sun, 05 Oct 2014 01:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=date:from:to:subject:message-id:references:mime-version:in-reply-to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type :content-disposition; bh=ycfvFj5ZbVlEmMAIphQjvZ6hEcIuNOsqVq5jl2MPzko=; b=UZ/MwVg8X72b1g/81Jz6vHFiXJ3UzURbsL5q7P2QCKBIIvr+9oDiF8YDWIscQyfxHu XrBR1oGKdyxdR40UdywsS76ilQNiNPDjzPMahp9Psoj0ErdTf91h3p1FVbQ+bDndZIUJ Eczi7y7bAQXeS/vV1qmFXtzElyyc41REGtsOwu0/kE7KTtAiIQ4SyJ7pWJ7k1dZX9Mw6 K3CaXmNTdog9cQMNwjOmo4ot6zpRzcEpyOdidpttnLsB+L4/kX5T+ABr5NjM2pp/d3vh d93rOMCBWYhefvHL2Q4M9k2SlfXy0AIEEeiSL+W2+PtxgryAFny35BRf7gJH3u2xnEQG RI4Q== X-Received: by 10.50.154.66 with SMTP id vm2mr68986igb.5.1412496927650; Sun, 05 Oct 2014 01:15:27 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.50.138.36 with SMTP id qn4ls689035igb.8.gmail; Sun, 05 Oct 2014 01:15:26 -0700 (PDT) X-Received: by 10.66.122.4 with SMTP id lo4mr8578080pab.23.1412496926668; Sun, 05 Oct 2014 01:15:26 -0700 (PDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net. [64.71.152.64]) by gmr-mx.google.com with ESMTP id yk10si1544806pac.0.2014.10.05.01.15.25 for ; Sun, 05 Oct 2014 01:15:25 -0700 (PDT) Received-SPF: none (google.com: e@80x24.org does not designate permitted sender hosts) client-ip=64.71.152.64; Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 67EED1F803; Sun, 5 Oct 2014 08:15:25 +0000 (UTC) Date: Sun, 5 Oct 2014 08:15:25 +0000 From: Eric Wong To: rack-devel@googlegroups.com Subject: [PATCH] conditionalget: avoid const lookup in case/when Message-ID: <20141005081525.GA8997@dcvr.yhbt.net> References: <20141003200836.GA4664@dcvr.yhbt.net> MIME-Version: 1.0 In-Reply-To: <20141003200836.GA4664@dcvr.yhbt.net> X-Original-Sender: e@80x24.org X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: e@80x24.org does not designate permitted sender hosts) smtp.mail=e@80x24.org Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline case/when dispatches already optimize away allocation of constant string literals in all C Ruby 1.9.x/2.x releases (ref: opt_case_dispatch in Ruby insns.def) Other Ruby implementations presumably have similar optimizations to encourage prettier code. The following code snippet does not cause GC.count to increase during the two loops, regardless of what `nr' is. Tested on Ruby 1.9.3, 2.1.3, and trunk r47786: GET = "GET" HEAD = "HEAD" REQUEST_METHOD = "REQUEST_METHOD" # unnecessary in 2.2.0+ env = { REQUEST_METHOD => "GET" } nr = 10000000 nr.times do |i| case env[REQUEST_METHOD] when GET, HEAD :foo else :bar end end a = GC.count nr.times do |i| case env[REQUEST_METHOD] when "GET", "HEAD" :foo else :bar end end b = GC.count p [ a, b ] --- Eric Wong wrote: > I don't disagree with this commit at this time OK, I disagree with one part :) I think the following allocations may be elided in future C Ruby, too: a) foo == "lit" (and "lit" == foo) b) str << "lit" If you prefer `git pull" for this: The following changes since commit 022b0076b0eacad03eac48060198f05aa776a866: Merge pull request #739 from schneems/schneems/fix-respond_to (2014-10-02 21:29:17 +0200) are available in the git repository at: git://bogomips.org/rack.git when-lit for you to fetch changes up to 68e086d2b42ee2c9fc8017264aa353a0d543fd13: conditionalget: avoid const lookup in case/when (2014-10-05 08:09:50 +0000) ---------------------------------------------------------------- Eric Wong (1): conditionalget: avoid const lookup in case/when lib/rack/conditionalget.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb index 3d4c78a..441dd38 100644 --- a/lib/rack/conditionalget.rb +++ b/lib/rack/conditionalget.rb @@ -21,7 +21,7 @@ module Rack def call(env) case env[REQUEST_METHOD] - when GET, HEAD + when "GET", "HEAD" status, headers, body = @app.call(env) headers = Utils::HeaderHash.new(headers) if status == 200 && fresh?(env, headers) -- EW -- --- You received this message because you are subscribed to the Google Groups "Rack Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.