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=-4.0 required=3.0 tests=AWL,BAYES_00, 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 668F81F66F for ; Wed, 4 Nov 2020 03:29:56 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C70761209A3; Wed, 4 Nov 2020 12:29:13 +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 01097120933 for ; Wed, 4 Nov 2020 12:29:11 +0900 (JST) Received: by filterdrecv-p3iad2-64988c98cc-49n5r with SMTP id filterdrecv-p3iad2-64988c98cc-49n5r-18-5FA2202A-14 2020-11-04 03:29:46.436834661 +0000 UTC m=+974093.985011373 Received: from herokuapp.com (unknown) by ismtpd0067p1mdw1.sendgrid.net (SG) with ESMTP id dOAuv9PzTcqs5y870_QmyA for ; Wed, 04 Nov 2020 03:29:46.349 +0000 (UTC) Date: Wed, 04 Nov 2020 03:29:46 +0000 (UTC) From: shyouhei@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76581 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17291 X-Redmine-Issue-Author: mrkn X-Redmine-Issue-Assignee: matz X-Redmine-Sender: shyouhei 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?jcfQDMoo=2FMGCmP3uu1SeyLQUxUPXq5PjHpHz3xSFn15LbNt0+qgEqEBhCucH2R?= =?us-ascii?Q?GlBXoTp+uYjMP7oSp2yppInoQ0=2F2MJqvszuDOZn?= =?us-ascii?Q?PIaco9L7hfcgi3BaT4vxq5gM6LaKofYGO8k3NhK?= =?us-ascii?Q?aQJbuO5stOtq0zDwPDIDMtZ2Gm9b1d753y10BJ5?= =?us-ascii?Q?OP1fdchEbXiWgi6e83WAUakLJfcxhUhp+Roem75?= =?us-ascii?Q?wh4Ggs5cDO9Cq+mQo=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100709 Subject: [ruby-core:100709] [Ruby master Feature#17291] Optimize __send__ call 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 #17291 has been updated by shyouhei (Shyouhei Urabe). It seems this leaks memory? ```ruby `nproc --all`.to_i.times.map do |i| Ractor.new i do |j| sleep rand k = 0 while true do __send__ :"#{j}_#{k+=1}" rescue nil printf("%d\n", GC.stat(:heap_live_slots)) if (k % 65535) == 0 end end end.map(&:take) ``` I see very different output comparing the proposed implementation versus master. ---------------------------------------- Feature #17291: Optimize __send__ call https://bugs.ruby-lang.org/issues/17291#change-88353 * Author: mrkn (Kenta Murata) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- I made a patch to optimize a `__send__` call. This optimization replaces a `__send__` method call with a call of the method whose name is the first argument of `__send__` method. The patch is available in [this pull-request](https://github.com/ruby/ruby/pull/3720). By this change, the redefined `__send__` method is no longer called when it is called by a symbol 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 proposal introduces two new instructions: `sendsym` and `opt_sendsym_without_block`. These instructions handle the cases that the first argument of `__send__` method is not a symbol literal. I think I can combine these two instructions into one if prefered. This proposal includes the change proposed in #17288. I'll mark it as a duplicate of this proposal. I don't handle `send` method in this proposal. The reason is that we need to examine the redefinition of `send` method in the instruction execution time. I want to discuss only `__send__` method in this ticket. The benchmark result is below: ``` # Iteration per second (i/s) | |compare-ruby|built-ruby| |:----------------|-----------:|---------:| |vm_send_sym | 18.001M| 112.208M| | | -| 6.23x| |vm_send_var | 17.779M| 30.922M| | | -| 1.74x| |vm_send_var_alt | 3.817M| 6.817M| | | -| 1.79x| ``` -- https://bugs.ruby-lang.org/