From: eregontp@... Date: 2020-08-15T10:54:17+00:00 Subject: [ruby-core:99595] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings Issue #17055 has been updated by Eregon (Benoit Daloze). I ran the measurements on both CRuby master and 2.6.6, with `sqlite3` for convenience. I see smaller differences, but also my results are about 6 times faster. It's still a larger difference than I expect so I'll try to dig deeper. Which version did you run with? Are you sure it's a build with default optimizations? Ruby master ``` $ ruby -v ruby 2.8.0dev (2020-08-15T05:17:02Z master d75433ae19) [x86_64-linux] $ gem i sequel benchmark-ips sqlite3 ``` ``` $ ruby bench_sequel_ivar.rb regular noplugin Warming up -------------------------------------- Retrieve 1000 rows 52.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 523.676 (� 0.8%) i/s - 2.652k in 5.064474s $ ruby bench_sequel_ivar.rb eager_initialize noplugin Warming up -------------------------------------- Retrieve 1000 rows 41.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 419.425 (� 0.2%) i/s - 2.132k in 5.083185s ``` 419.425 / 523.676 = 0.80, 20% slower ``` $ gem i activemodel $ ruby bench_sequel_ivar.rb regular plugin Warming up -------------------------------------- Retrieve 1000 rows 43.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 435.382 (� 0.5%) i/s - 2.193k in 5.037051s $ ruby bench_sequel_ivar.rb eager_initialize plugin Warming up -------------------------------------- Retrieve 1000 rows 29.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 292.735 (� 0.3%) i/s - 1.479k in 5.052414s ``` 292.735 / 435.382 = 0.67, 33% slower ``` Ruby 2.6 $ ruby -v ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux] ``` ``` $ ruby bench_sequel_ivar.rb regular noplugin Warming up -------------------------------------- Retrieve 1000 rows 49.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 491.918 (� 0.4%) i/s - 2.499k in 5.080182s $ ruby bench_sequel_ivar.rb eager_initialize noplugin Warming up -------------------------------------- Retrieve 1000 rows 40.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 396.391 (� 1.3%) i/s - 2.000k in 5.046391s ``` 396.391 / 491.918 = 0.81, 19% slower ``` $ gem i activemodel $ ruby bench_sequel_ivar.rb regular plugin Warming up -------------------------------------- Retrieve 1000 rows 44.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 443.197 (� 0.2%) i/s - 2.244k in 5.063244s $ ruby bench_sequel_ivar.rb eager_initialize plugin Warming up -------------------------------------- Retrieve 1000 rows 27.000 i/100ms Calculating ------------------------------------- Retrieve 1000 rows 273.062 (� 0.4%) i/s - 1.377k in 5.042868s ``` 273.062 / 443.197 = 0.62, 38% slower ---------------------------------------- Feature #17055: Allow suppressing uninitialized instance variable and method redefined verbose mode warnings https://bugs.ruby-lang.org/issues/17055#change-87073 * 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/ Unsubscribe: