[#99856] [Ruby master Feature#17143] Improve support for warning categories — merch-redmine@...

Issue #17143 has been reported by jeremyevans0 (Jeremy Evans).

16 messages 2020/09/03

[#99868] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file — eregontp@...

Issue #17144 has been reported by Eregon (Benoit Daloze).

15 messages 2020/09/03

[#99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` — marcandre-ruby-core@...

Issue #17145 has been reported by marcandre (Marc-Andre Lafortune).

32 messages 2020/09/03

[#99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen — eregontp@...

Issue #17146 has been reported by Eregon (Benoit Daloze).

16 messages 2020/09/03

[#100016] [Ruby master Feature#17171] Why is the visibility of constants not affected by `private`? — marcandre-ruby-core@...

Issue #17171 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/09/15

[#100024] [Ruby master Bug#17175] Ruby 2.5: OpenSSL related test failures — jaruga@...

Issue #17175 has been reported by jaruga (Jun Aruga).

10 messages 2020/09/16

[#100025] [Ruby master Feature#17176] GC.enable_autocompact / GC.disable_autocompact — tenderlove@...

Issue #17176 has been reported by tenderlovemaking (Aaron Patterson).

11 messages 2020/09/16

[#100099] [Ruby master Bug#17184] No stdlib function to perform simple string replacement — sheerun@...

Issue #17184 has been reported by sheerun (Adam Stankiewicz).

18 messages 2020/09/24

[#100192] [Ruby master Bug#17197] Some Hash methods still have arity 2 instead of 1 — marcandre-ruby-core@...

Issue #17197 has been reported by marcandre (Marc-Andre Lafortune).

14 messages 2020/09/28

[#100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa — baptiste.courtois@...

Issue #17199 has been reported by Annih (Baptiste Courtois).

7 messages 2020/09/28

[#100206] [Ruby master Misc#17200] DevelopersMeeting20201026Japan — mame@...

Issue #17200 has been reported by mame (Yusuke Endoh).

18 messages 2020/09/28

[#100239] [Ruby master Feature#17206] Introduce new Regexp option to avoid MatchData allocation — fatkodima123@...

Issue #17206 has been reported by fatkodima (Dima Fatko).

8 messages 2020/09/30

[ruby-core:100079] [Ruby master Feature#4917] NilClass#to_ary

From: danzoid61@...
Date: 2020-09-23 00:43:13 UTC
List: ruby-core #100079
Issue #4917 has been updated by DanRathbun (Dan Rathbun).


y_feldblum (Jay Feldblum) wrote in #note-6:
> This minor performance issue becomes a huge problem when NilClass#method_missing is defined, such as in ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/whiny_nil.rb), which is a popular choice when developing a Rails application.
> 

I'm curious, now that Ruby 2.x has refinements (and we're near 10 years on,) would there be acceptable speed improvements using refinements rather than direct-patching (ie, hacks) ?

----------------------------------------
Feature #4917: NilClass#to_ary
https://bugs.ruby-lang.org/issues/4917#change-87636

* Author: y_feldblum (Jay Feldblum)
* Status: Rejected
* Priority: Normal
----------------------------------------
As a performance improvement in certain cases, nil should respond to to_ary.

Kernel#Array, when passed nil, first tries to send to_ary to nil (which actually ends up calling method_missing on nil) and then tries to send to_a to nil which finally succeeds. When Kernel#Array is used often, for example in library/gem code, this can have a noticeable, if relatively small, negative impact on the overall application performance.

    $ irb

    > RUBY_VERSION
     => "1.9.2"

    > require 'benchmark'
    > def bench(times) Benchmark.bmbm{|x| x.report{times.times(&Proc.new)}} end

    # Let's zero the scale....
    > bench(10_000_000) { }

    # The "before" benchmark....
    > bench(10_000_000) { Array(nil) }

    # An optimization....
    > NilClass.class_eval { alias to_ary to_a }

    # The "after" benchmark....
    > bench(10_000_000) { Array(nil) }
    # Much faster!

    # Let's see how many times method_missing actually gets called....
    > NilClass.class_eval { undef to_ary }
    > class NilClass
    >   alias method_missing_without_hit method_missing
    >   def method_missing(name, *args, &block)
    >     $method_missing_hits += 1
    >     method_missing_without_hit(name, *args, &block)
    >   end
    > end

    > $method_missing_hits = 0
    > bench(100_000) { Array(nil) }
    # Very slow!
    > $method_missing_hits
     => 200005

    > NilClass.class_eval { alias to_ary to_a }
    > $method_missing_hits = 0
    > bench(100_000) { Array(nil) }
    # Instantaneous!
    > $method_missing_hits
     => 0




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next