From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 725CF1F5AE for ; Mon, 20 Jul 2020 10:27:17 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id a14so2426250wra.5 for ; Mon, 20 Jul 2020 03:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopify.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RCIyougHHm+0Item7ub+fG697S/oTtsTYrNgwA5mNMw=; b=YM4auzA2HFSvotHWGrXF15C2yPMwSg8CVcNWnNMoFQ5GUspLFKA7o3v3LbMF5obkX7 WmeqDcf3Gn+dsdtbOmYYxQZo1qM7Iwqkts9RsPav66eL1v2pMWXeVjyJuIvL1YjB9l5P c0as5dutL2w3TGJ+e/QMRU0q0eQP82dQh2x+Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RCIyougHHm+0Item7ub+fG697S/oTtsTYrNgwA5mNMw=; b=De2GC7ELUD8vYH3v20aJDChVnb7tEwoOQPcAxDLnpwLYopQ0sXkWpb7ibrelfJeBju WPyfpNiq7rzqps2rPwuWHHeLNEC9jENaPfnnPq4xKrwL+7YNgmi+HfSAoOuq8SjTlnNM Ohjz5r6Qzr0cV9+d3S3nm+P6tbQE0kBGdvFciS4vL7Em5qorEYNUYYaRdCVjMxucLhOw biwiLFeKK6IYNtLPLTrXU6gC47ciMHzdQY4DFTLLGgZVUaVG8w9BxnDb9ciCBeAM10w1 j5QVu40B9YlPFNG90reZ4Pw1dHhcRhvu6hRS3G2TgfXhvT8GsDcyAKN0WsMZxZeL1w45 0zxA== X-Gm-Message-State: AOAM531P6VBYWV12Mqdo3FjxLQ36R+ew1jgNGmVHx6yrnAn0Hl5J4cDA MSVLKadc2RRzOMp84LMlefy5+Q== X-Google-Smtp-Source: ABdhPJzDI40U09hDmrI6oXMubEZ+5t+T+zy3lKhhNvOY39IAQ/64OEJKF4B5x0RVaPIdfSTutxgdxQ== X-Received: by 2002:a5d:65cd:: with SMTP id e13mr23344972wrw.213.1595240835845; Mon, 20 Jul 2020 03:27:15 -0700 (PDT) Received: from [192.168.0.12] (87-231-62-161.rev.numericable.fr. [87.231.62.161]) by smtp.gmail.com with ESMTPSA id a11sm9221502wrq.0.2020.07.20.03.27.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 03:27:15 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH] Add early hints support From: Jean Boussier In-Reply-To: <20200720100958.GA7043@dcvr> Date: Mon, 20 Jul 2020 12:27:14 +0200 Cc: unicorn-public@yhbt.net Content-Transfer-Encoding: quoted-printable Message-Id: References: <058BA238-BEB3-4E54-9DE6-DC59BCB86246@shopify.com> <20200716105037.GA26605@dcvr> <242F0859-0F83-4F14-A0FF-5BE392BB01E6@shopify.com> <20200716121643.GA26942@dcvr> <20200717011955.GA23522@dcvr> <624157B8-884C-42EB-8515-AFC6807D6F8D@shopify.com> <20200720100958.GA7043@dcvr> To: Eric Wong X-Mailer: Apple Mail (2.3608.80.23.2.2) List-Id: > `match?' is Ruby 2.4+, which is probably too big a jump since > we're still on Ruby 1.9.3 at the moment... That's what I figured. > String comparison as in `=3D=3D' and `!=3D'? Would be interested to = know > where and what improvements can be had. One place that jumped to mind when I saw it is http_response_write. But there are many other places where Regexp are used to do case insensitive comparisons. ``` require 'benchmark/ips' def http_response_write(headers) headers.each do |key, value| case key when %r{\A(?:Date|Connection)\z}i next end end end def http_response_write_upcase(headers) headers.each do |key, value| case key.upcase when 'DATE'.freeze, 'CONNECTION'.freeze next end end end def http_response_write_casecmp(headers) headers.each do |key, value| case key when key.casecmp?('Date'.freeze) || = key.casecmp?('Connection'.freeze) next end end end HEADERS =3D { 'Foo' =3D> 'bar', 'Date' =3D> 'plop', 'User-Agent' =3D> 'blah', } Benchmark.ips do |x| x.report('original') { http_response_write(HEADERS) } x.report('upcase') { http_response_write_upcase(HEADERS) } x.report('casecmp?') { http_response_write_casecmp(HEADERS) } x.compare! end ``` ``` Warming up -------------------------------------- original 82.066k i/100ms upcase 177.429k i/100ms casecmp? 96.288k i/100ms Calculating ------------------------------------- original 831.610k (=C2=B1 1.6%) i/s - 4.185M in = 5.034146s upcase 1.770M (=C2=B1 1.6%) i/s - 8.871M in = 5.013796s casecmp? 979.618k (=C2=B1 1.3%) i/s - 4.911M in = 5.013678s Comparison: upcase: 1769883.2 i/s casecmp?: 979618.3 i/s - 1.81x (=C2=B1 0.00) slower original: 831610.2 i/s - 2.13x (=C2=B1 0.00) slower ``` Similarly, that method use `value =3D~ /\n/` which could be replaced favorably for `value.include?("\n".freeze)` ``` VAL =3D "foobar" Benchmark.ips do |x| x.report('=3D~') { VAL =3D~ /\n/ } x.report('include?') { VAL.include?("\n".freeze) } x.compare! end ``` ``` Warming up -------------------------------------- =3D~ 409.096k i/100ms include? 1.322M i/100ms Calculating ------------------------------------- =3D~ 4.083M (=C2=B1 2.1%) i/s - 20.455M in = 5.011539s include? 13.053M (=C2=B1 1.5%) i/s - 66.125M in = 5.067097s Comparison: include?: 13052859.2 i/s =3D~: 4083401.3 i/s - 3.20x (=C2=B1 0.00) slower ``` > Ruby just seems hopeless performance-wise=20 Well, the gap between 1.9.3 and 2.5+ is pretty big performance-wise.