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.6 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 065B01F66E for ; Fri, 28 Aug 2020 15:01:14 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 50838120ACE; Sat, 29 Aug 2020 00:00:39 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 882D5120ACD for ; Sat, 29 Aug 2020 00:00:37 +0900 (JST) Received: by filterdrecv-p3las1-75ccf54874-9d2v5 with SMTP id filterdrecv-p3las1-75ccf54874-9d2v5-19-5F491C30-159 2020-08-28 15:01:05.064128727 +0000 UTC m=+75667.208133093 Received: from herokuapp.com (unknown) by ismtpd0016p1iad2.sendgrid.net (SG) with ESMTP id JRfaSKNPRAK17DLGsLsSNA for ; Fri, 28 Aug 2020 15:01:04.936 +0000 (UTC) Date: Fri, 28 Aug 2020 15:01:05 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75583 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17030 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr1qQZM+=2FYCg0=2FperFALPg?= =?us-ascii?Q?8aN7QrSLTyg4BZfclQHgIdDqHTWSz05R4+zs5Ht?= =?us-ascii?Q?o3az2nx3Vj=2FgBL0KbMTSNwPMDCKfqS8hJpK2LW+?= =?us-ascii?Q?k7rmcYcJrHX0jxtakksEGaRf=2FVWp9O5NR1pPelS?= =?us-ascii?Q?BgpYGoBQH=2F+18yFAxSfPMjDThKADd2ruVT79A54?= =?us-ascii?Q?3kcBUqCvX3TO0j0B4=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99751 Subject: [ruby-core:99751] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17030 has been updated by Eregon (Benoit Daloze). This is something that a JIT with inlining and escape analysis can optimize= and always be correct. Static analysis doesn't cut it for Ruby. On TruffleRuby (master + a fix I'll merge soon) for the benchmark above: ``` Calculating ------------------------------------- select.match? 2.503M (=B1 2.9%) i/s - 12.677M in 5.068796s grep 2.502M (=B1 2.8%) i/s - 12.558M in 5.022837s select.match? 2.519M (=B1 2.6%) i/s - 12.677M in 5.036105s grep 2.498M (=B1 2.2%) i/s - 12.558M in 5.030485s Comparison: select.match?: 2518943.6 i/s grep: 2497618.0 i/s - same-ish: difference falls within er= ror ``` MRI 2.6 for comparison: ``` Calculating ------------------------------------- select.match? 943.017k (=B1 0.6%) i/s - 4.770M in 5.058962s grep 470.844k (=B1 0.8%) i/s - 2.389M in 5.074917s select.match? 944.326k (=B1 0.7%) i/s - 4.770M in 5.052020s grep 471.122k (=B1 2.5%) i/s - 2.389M in 5.074969s Comparison: select.match?: 944325.5 i/s grep: 471122.3 i/s - 2.00x (=B1 0.00) slower ``` ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87251 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Currently, ```ruby array.select { |e| e.match?(REGEXP) } ``` is about three times faster and six times more memory efficient than ```ruby array.grep(REGEXP) ``` This is because `grep` calls `Regexp#=3D=3D=3D`, which creates useless `Mat= chData`. -- = https://bugs.ruby-lang.org/ Unsubscribe: