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=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham 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 69DA91F66F for ; Thu, 29 Oct 2020 04:06:23 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4938E120B1C; Thu, 29 Oct 2020 13:05:40 +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 713081209D1 for ; Thu, 29 Oct 2020 13:05:37 +0900 (JST) Received: by filterdrecv-p3mdw1-5b99b59cbc-6nq26 with SMTP id filterdrecv-p3mdw1-5b99b59cbc-6nq26-20-5F9A3FB5-33 2020-10-29 04:06:13.779751063 +0000 UTC m=+185148.813534141 Received: from herokuapp.com (unknown) by ismtpd0024p1iad2.sendgrid.net (SG) with ESMTP id fPb8kt_CQxesnjFvtNnxLA for ; Thu, 29 Oct 2020 04:06:13.684 +0000 (UTC) Date: Thu, 29 Oct 2020 04:06:13 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76504 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17288 X-Redmine-Issue-Author: mrkn X-Redmine-Issue-Assignee: matz X-Redmine-Sender: marcandre 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?6=2FIMxCQLDposcQf5wmbDAtfaKduBAO0bKyhL3BGZtMQ5q7K2TvpbN6A7JIyt9E?= =?us-ascii?Q?aO4bTb13J76CJEjhOD2+QCp5rHoaGdYxC7UNEAH?= =?us-ascii?Q?btmMufrjdI4nbCWUYMQBmkYh3mFtgVerxDKV2kd?= =?us-ascii?Q?s7Ka0ntsn9lw6H6Ki50PXomB+vQooWcjdQQK2aK?= =?us-ascii?Q?k0aljCQNtcXk9EyANO4LHutG5f=2FnGpYHr14ggxW?= =?us-ascii?Q?NPMbdhnwwa2tYluoIyneAS32hsFxjJJjmlSTy4?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100632 Subject: [ruby-core:100632] [Ruby master Feature#17288] Optimize __send__ call with a literal method name 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 #17288 has been updated by marcandre (Marc-Andre Lafortune). shyouhei (Shyouhei Urabe) wrote in #note-9: > @marcandre Here you are: > > [snip brilliant code] 0) I was wrong, I retract what I said. 1) My mind is blown. I have always thought of refinements as a way to safely monkey-patch other people's classes, in particular builtin classes. Never as a way to structure access to our own classes. This can also be very fine-grained if desired. This is brilliant @shyouhei! 2) Goto 1 I made a quick POC with RuboCop to isolate methods that I've always wanted to isolate and the only issues was mocking internal methods: ``` Failure/Error: allow(cop).to receive(:complete_investigation).and_return(cop_report) # does not implement: complete_investigation ``` I'm fine with this, I already try to avoid stub and mocks anyways (10 tests out of 14515 :-) and I'm sure I can find better ways around that. I also wanted to check any performance impact. I couldn't see any (running tests or running RuboCop). Are there any known circumstances where performance would be affected? Are there gems using this technique? Blog posts discussing this? ---------------------------------------- Feature #17288: Optimize __send__ call with a literal method name https://bugs.ruby-lang.org/issues/17288#change-88267 * Author: mrkn (Kenta Murata) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- I made a patch to optimize a `__send__` call with a literal method name. This optimization replaces a `__send__` method call with a `send` instruction. The patch is available in [this pull-request](https://github.com/ruby/ruby/pull/3707). By this change, the redefined `__send__` method is no longer called when it is called by a literal method name. I guess it is no problem because the following warning message is displayed for a long time. $ ruby -e 'def __send__; end' -e:1: warning: redefining `__send__' may cause serious problems This change makes the optimized case x5~x6 faster. The benchmark result is below: ``` $ make benchmark COMPARE_RUBY="../../ruby/build-o3/ruby" ITEM=vm_send.yml (snip) # Iteration per second (i/s) | |compare-ruby|built-ruby| |:------------|-----------:|---------:| |vm_send | 18.536M| 113.778M| | | -| 6.14x| |vm_send_var | 18.085M| 16.595M| | | 1.09x| -| ``` -- https://bugs.ruby-lang.org/