From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.25.37.80 with SMTP id l77csp102938lfl; Sun, 5 Oct 2014 14:37:30 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBD75LW742ECRBGHUY2QQKGQEXLYADFQ@googlegroups.com designates 10.152.28.66 as permitted sender) client-ip=10.152.28.66 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBD75LW742ECRBGHUY2QQKGQEXLYADFQ@googlegroups.com designates 10.152.28.66 as permitted sender) smtp.mail=rack-devel+bncBD75LW742ECRBGHUY2QQKGQEXLYADFQ@googlegroups.com; dkim=pass header.i=@googlegroups.com X-Received: from mr.google.com ([10.152.28.66]) by 10.152.28.66 with SMTP id z2mr2869451lag.3.1412545050613 (num_hops = 1); Sun, 05 Oct 2014 14:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:in-reply-to:references:date:message-id:subject:from: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; bh=K3rO/YWjLQ5wLnAL0JPtC6YiKlzYrvXnai0JejXydRo=; b=OmxiGNOIHAWjdMPBAGy8nNoHdSrsnQYpiwzFKGOHH+B31X0WCUVP0yh2vq18WBorbl PNcrdAG3jcZ8Q+iyWLOaewm7nPToZzEDaLUsfhz12zjvRaaabPnc+rLkVpbdCpjrhzLN dyW4ddzdI9Deee8HLR3ipQQF/PHm/5oiStudGXuEOqhKVU04OyooL31CV0/F6BmrsB8X OpIirKK1usD2FJyLF7UbU12IP9UZ65NULeWKh565wzjU+3dpXotvVUJ66DlIB1JZtbfo Rs5ii7B/zTTf4yLII+TrV+TTYlHC/LfaYSmxhtnnD9Hsw76nhdCijtiDD9OZqEzKc3VA 3V7g== X-Received: by 10.152.28.66 with SMTP id z2mr316899lag.3.1412545050570; Sun, 05 Oct 2014 14:37:30 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.152.6.134 with SMTP id b6ls461529laa.77.gmail; Sun, 05 Oct 2014 14:37:28 -0700 (PDT) X-Received: by 10.112.205.70 with SMTP id le6mr3127520lbc.4.1412545048209; Sun, 05 Oct 2014 14:37:28 -0700 (PDT) Received: from mail-la0-x22b.google.com (mail-la0-x22b.google.com [2a00:1450:4010:c03::22b]) by gmr-mx.google.com with ESMTPS id us10si1191543lbc.1.2014.10.05.14.37.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 Oct 2014 14:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of jftucker@gmail.com designates 2a00:1450:4010:c03::22b as permitted sender) client-ip=2a00:1450:4010:c03::22b; Received: by mail-la0-f43.google.com with SMTP id mc6so3433621lab.30 for ; Sun, 05 Oct 2014 14:37:28 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.87.170 with SMTP id az10mr20858755lab.20.1412545048107; Sun, 05 Oct 2014 14:37:28 -0700 (PDT) Received: by 10.152.27.38 with HTTP; Sun, 5 Oct 2014 14:37:28 -0700 (PDT) In-Reply-To: <20141005081525.GA8997@dcvr.yhbt.net> References: <20141003200836.GA4664@dcvr.yhbt.net> <20141005081525.GA8997@dcvr.yhbt.net> Date: Sun, 5 Oct 2014 14:37:28 -0700 Message-ID: Subject: Re: [PATCH] conditionalget: avoid const lookup in case/when From: James Tucker To: rack-devel@googlegroups.com X-Original-Sender: jftucker@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jftucker@gmail.com designates 2a00:1450:4010:c03::22b as permitted sender) smtp.mail=jftucker@gmail.com; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com 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: multipart/alternative; boundary=001a11c223b6d262d20504b3c5bc --001a11c223b6d262d20504b3c5bc Content-Type: text/plain; charset=UTF-8 Thanks Eric! On Sun, Oct 5, 2014 at 1:15 AM, Eric Wong wrote: > 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. > -- --- 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. --001a11c223b6d262d20504b3c5bc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks Eric!

On Sun, Oct 5, 2014 at 1:15 AM, Eric Wong <e@80x24.org>= wrote:
case/when dispatches alrea= dy 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:

=C2=A0 =C2=A0 GET =3D "GET"
=C2=A0 =C2=A0 HEAD =3D "HEAD"
=C2=A0 =C2=A0 REQUEST_METHOD =3D "REQUEST_METHOD" # unnecessary i= n 2.2.0+
=C2=A0 =C2=A0 env =3D { REQUEST_METHOD =3D> "GET" }

=C2=A0 =C2=A0 nr =3D 10000000
=C2=A0 =C2=A0 nr.times do |i|
=C2=A0 =C2=A0 =C2=A0 case env[REQUEST_METHOD]
=C2=A0 =C2=A0 =C2=A0 when GET, HEAD
=C2=A0 =C2=A0 =C2=A0 =C2=A0 :foo
=C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 :bar
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end
=C2=A0 =C2=A0 a =3D GC.count

=C2=A0 =C2=A0 nr.times do |i|
=C2=A0 =C2=A0 =C2=A0 case env[REQUEST_METHOD]
=C2=A0 =C2=A0 =C2=A0 when "GET", "HEAD"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 :foo
=C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 :bar
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end
=C2=A0 =C2=A0 b =3D GC.count
=C2=A0 =C2=A0 p [ a, b ]
---
=C2=A0 Eric Wong <e@80x24.org> wro= te:
=C2=A0 > I don't disagree with this commit at this time

=C2=A0 OK, I disagree with one part :)

=C2=A0 I think the following allocations may be elided in future C Ruby, to= o:
=C2=A0 =C2=A0 a) foo =3D=3D "lit" (and "lit" =3D=3D foo= )
=C2=A0 =C2=A0 b) str << "lit"

=C2=A0 If you prefer `git pull" for this:

=C2=A0 The following changes since commit 022b0076b0eacad03eac48060198f05aa= 776a866:

=C2=A0 =C2=A0 Merge pull request #739 from schneems/schneems/fix-respond_to= (2014-10-02 21:29:17 +0200)

=C2=A0 are available in the git repository at:

=C2=A0 =C2=A0 git://bogomips.org/rack.git when-lit

=C2=A0 for you to fetch changes up to 68e086d2b42ee2c9fc8017264aa353a0d543f= d13:

=C2=A0 =C2=A0 conditionalget: avoid const lookup in case/when (2014-10-05 0= 8:09:50 +0000)

=C2=A0 ----------------------------------------------------------------
=C2=A0 Eric Wong (1):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 conditionalget: avoid const lookup in case/when=

=C2=A0lib/rack/conditionalget.rb | 2 +-
=C2=A01 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

=C2=A0 =C2=A0 =C2=A0def call(env)
=C2=A0 =C2=A0 =C2=A0 =C2=A0case env[REQUEST_METHOD]
-=C2=A0 =C2=A0 =C2=A0 when GET, HEAD
+=C2=A0 =C2=A0 =C2=A0 when "GET", "HEAD"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0status, headers, body =3D @app.call(env)<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0headers =3D Utils::HeaderHash.new(headers= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if status =3D=3D 200 && fresh?(en= v, headers)
--
EW

--

---
You received this message because you are subscribed to the Google Groups &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-d= evel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-dev= el+unsubscribe@googlegroups.com.
For more options, visit http= s://groups.google.com/d/optout.
--001a11c223b6d262d20504b3c5bc--