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, 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 939601F5AE for ; Mon, 3 Aug 2020 17:01:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BF6B4120A46; Tue, 4 Aug 2020 02:01:05 +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 8F7A9120A45 for ; Tue, 4 Aug 2020 02:01:03 +0900 (JST) Received: by filterdrecv-p3mdw1-7ff865655c-hpdqc with SMTP id filterdrecv-p3mdw1-7ff865655c-hpdqc-19-5F2842E6-101 2020-08-03 17:01:26.875984179 +0000 UTC m=+427516.070690730 Received: from herokuapp.com (unknown) by ismtpd0018p1iad2.sendgrid.net (SG) with ESMTP id MBJ_2r7KTKaz5nX0a7OD-Q for ; Mon, 03 Aug 2020 17:01:26.843 +0000 (UTC) Date: Mon, 03 Aug 2020 17:01:26 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75289 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17055 X-Redmine-Issue-Author: jeremyevans0 X-Redmine-Sender: jeremyevans0 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?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIGaeWXt7Iqg8e4oIce=2FjVZCYKQxyou3NMwuClV?= =?us-ascii?Q?cGW46qFKoIeRLapi548AGyNzhAlW7S2h2ahdR=2FO?= =?us-ascii?Q?18Ba2CXqKLtJzXt8zSxItvYNKh4HZ8adOr2uHc9?= =?us-ascii?Q?nCy5s0YBL05322iGHHZBTFAxIbjJ7RBzwHTPCN9?= =?us-ascii?Q?8hZeY4Hn=2FZS6HmOKk=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99459 Subject: [ruby-core:99459] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings 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 #17055 has been updated by jeremyevans0 (Jeremy Evans). tenderlovemaking (Aaron Patterson) wrote in #note-14: > jeremyevans0 (Jeremy Evans) wrote in #note-13: > > As you'll see by the benchmark, the reason the performance difference is much different than you would expect is that Model loads from the database in Sequel run through `Sequel::Model.call` (class method, not instance method), and all of the plugins that use instance variables must override the method to set the instance variables. Because it is a class method and not an instance method, `instance_variable_set` must be used. The overhead of all of those additional method calls (`super` and `instance_variable_set`) is what causes the dramatic difference in performance. > > Could the design be improved such that `instance_variable_set` isn't required? Using `instance_variable_set` means that inline caches will not be used (in MRI anyway), so I'm not sure it should be used in code that requires high performance. I suppose we could also work on improving the performance of `instance_variable_set`, but I'm not sure usage is _that_ common. It certainly could, but it would require more work, and would result in slower performance in the the no-plugin case. We could add a private instance method can call that, and the private instance method could initialize all the instance variables to nil the usual way. That would make things somewhat faster. You still have all the super calls to slow things down, though. If you want me to work on a benchmark for that, please let me know, but it's a sure bet that even that approach would result in a slowdown significant enough that I wouldn't want to switch to it. ---------------------------------------- Feature #17055: Allow suppressing uninitialized instance variable and method redefined verbose mode warnings https://bugs.ruby-lang.org/issues/17055#change-86916 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Priority: Normal ---------------------------------------- These two verbose mode warnings are both fairly common and have good reasons why you would not want to warn about them in specific cases. Not initializing instance variables to nil can be much better for performance, and redefining methods without removing the method first is the only safe approach in multi-threaded code. There are reasons that you may want to issue verbose warnings by default in these cases. For uninitialized instance variables, it helps catch typos. For method redefinition, it could alert you that a method already exists when you didn't expect it to, such as when a file is loaded multiple times when it should only be loaded once. I propose we keep the default behavior the same, but offer the ability to opt-out of these warnings by defining methods. For uninitialized instance variables in verbose mode, I propose we call `expected_uninitialized_instance_variable?(iv)` on the object. If this method doesn't exist or returns false/nil, we issue the warning. If the method exists and returns true, we suppress the warning. Similarly, for redefined methods, we call `expected_redefined_method?(method_name)` on the class or module. If the method doesn't exist or returns false/nil, we issue the warning. If the method exists and returns true, we suppress the warning. This approach allows high performance code (uninitialized instance variables) and safe code (redefining methods without removing) to work without verbose mode warnings. I have implemented this support in a pull request: https://github.com/ruby/ruby/pull/3371 ---Files-------------------------------- t.rb (5.59 KB) -- https://bugs.ruby-lang.org/