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 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 7931D1F66E for ; Wed, 26 Aug 2020 17:01:38 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6DE7A120A1C; Thu, 27 Aug 2020 02:01:03 +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 030C3120A10 for ; Thu, 27 Aug 2020 02:01:00 +0900 (JST) Received: by filterdrecv-p3las1-c889d8879-lgdr7 with SMTP id filterdrecv-p3las1-c889d8879-lgdr7-17-5F469565-25 2020-08-26 17:01:25.186174023 +0000 UTC m=+77445.340852240 Received: from herokuapp.com (unknown) by ismtpd0063p1mdw1.sendgrid.net (SG) with ESMTP id 0QcOscpFRc-2G1ejCq3QPw for ; Wed, 26 Aug 2020 17:01:24.998 +0000 (UTC) Date: Wed, 26 Aug 2020 17:01:25 +0000 (UTC) From: fatkodima123@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75539 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17030 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: fatkodima 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?RvZ0H4gD69HjmyxuoEldmMenU4znNUKl7mOsZIogdq4iVLYOM=2Fi6tzUhfhvJc9?= =?us-ascii?Q?yFaXU5W=2FT49IxDXm2HH6EOkoYKsu7P7dJJzDX4u?= =?us-ascii?Q?Yihg1FKRvJeEEwz9KjckZ6ffM9FLgaD9oIT+rDJ?= =?us-ascii?Q?wkZpEtdcRrKecaZKAV42J4XBpZCnBaxvjncNeAG?= =?us-ascii?Q?1rb1eUljBN0lK=2FtJP15cqVSWveoSVANCnrBukfG?= =?us-ascii?Q?9Yfd=2F0jXpP97XSWaQ=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99706 Subject: [ruby-core:99706] [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="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17030 has been updated by fatkodima (Dima Fatko). marcandre (Marc-Andre Lafortune) wrote in #note-12: > Maybe it would be best to start a different thread as none of these proposals have a relation to `grep{_v}` without block not being optimized. I have already implemented a patch to make `grep{_v}` faster and right before submitting the `Create Pull Request` button, I realized (with the help of scivola20's comment), that this case can be generalized. Because we already have, at least, `Enumerable#{all?,any?,none?}` and many future methods to be added (like `grep`), which can benefit from this generalized solution. > This is Ruby, so I can think of some corner cases where things like `const_get(:Regexp).last_match` would be impacted (in theory), what other limitations would this have? > `case-when`? > Couldn't static analysis of the code determine in most cases if match data need be generated or not? > In many cases, probably yes, but again, `case-when`. ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87197 * 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) } # about 3x faster and 6x more memory efficient than array.grep(REGEXP) ``` This is because `grep` calls `Regexp#===` which creates useless `MatchData` -- https://bugs.ruby-lang.org/