Koichi Sasada cfd7729ce7 use inline cache for refinements
From Ruby 3.0, refined method invocations are slow because
resolved methods are not cached by inline cache because of
conservertive strategy. However, `using` clears all caches
so that it seems safe to cache resolved method entries.

This patch caches resolved method entries in inline cache
and clear all of inline method caches when `using` is called.

fix [Bug #18572]

```ruby
 # without refinements

class C
  def foo = :C
end

N = 1_000_000

obj = C.new
require 'benchmark'
Benchmark.bm{|x|
  x.report{N.times{
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
  }}
}

_END__
              user     system      total        real
master    0.362859   0.002544   0.365403 (  0.365424)
modified  0.357251   0.000000   0.357251 (  0.357258)
```

```ruby
 # with refinment but without using

class C
  def foo = :C
end

module R
  refine C do
    def foo = :R
  end
end

N = 1_000_000

obj = C.new
require 'benchmark'
Benchmark.bm{|x|
  x.report{N.times{
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
  }}
}
__END__
               user     system      total        real
master     0.957182   0.000000   0.957182 (  0.957212)
modified   0.359228   0.000000   0.359228 (  0.359238)
```

```ruby
 # with using

class C
  def foo = :C
end

module R
  refine C do
    def foo = :R
  end
end

N = 1_000_000

using R

obj = C.new
require 'benchmark'
Benchmark.bm{|x|
  x.report{N.times{
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
    obj.foo; obj.foo; obj.foo; obj.foo; obj.foo;
  }}
}
2023-07-31 17:13:43 +09:00
2023-07-30 19:38:18 +09:00
2023-07-27 15:30:10 -07:00
2023-06-08 17:25:38 +09:00
2023-07-14 18:35:23 +09:00
2023-07-31 17:13:43 +09:00
2023-07-27 17:27:05 -07:00
2023-07-05 14:10:13 -07:00
2023-05-27 02:07:47 +09:00
2023-06-29 17:00:40 -04:00
2023-07-13 14:48:14 -04:00
2023-06-12 18:23:48 +09:00
2023-06-30 14:59:34 +00:00
2023-07-13 09:21:36 +01:00
2023-07-27 17:27:05 -07:00
2023-07-27 17:27:05 -07:00
2023-07-21 15:44:24 -04:00
2023-07-23 10:24:19 -04:00
2023-07-30 01:02:20 +09:00
2023-07-31 17:13:43 +09:00
2023-07-31 17:13:43 +09:00
GPL
2023-07-13 14:48:14 -04:00
2023-07-13 09:27:33 -04:00
2023-07-28 10:51:11 +09:00
2023-07-27 17:27:05 -07:00
2023-07-28 19:39:43 +09:00
2023-07-17 23:57:11 +09:00
2023-07-31 17:13:43 +09:00
2023-07-31 06:59:54 +00:00
2023-06-12 18:23:48 +09:00
2023-07-26 11:39:29 +09:00
2023-07-27 15:30:10 -07:00
2023-07-27 13:33:40 -04:00
2023-07-28 22:17:53 +09:00
2023-06-20 09:28:21 -04:00
2023-07-04 21:30:44 +09:00
2023-07-19 14:35:43 +09:00
2023-07-13 14:48:14 -04:00
2023-07-13 16:49:39 -07:00
2023-07-13 14:48:14 -04:00
2023-07-31 17:13:43 +09:00
2023-07-31 17:13:43 +09:00
2023-07-27 17:27:05 -07:00
2023-07-31 17:13:43 +09:00
2023-07-27 17:27:05 -07:00
2023-07-31 17:13:43 +09:00
2023-07-27 17:27:05 -07:00

Actions Status: MinGW Actions Status: RJIT Actions Status: Ubuntu Actions Status: Windows AppVeyor status Travis Status Cirrus Status

What is Ruby?

Ruby is an interpreted object-oriented programming language often used for web development. It also offers many scripting features to process plain text and serialized files, or manage system tasks. It is simple, straightforward, and extensible.

Features of Ruby

  • Simple Syntax
  • Normal Object-oriented Features (e.g. class, method calls)
  • Advanced Object-oriented Features (e.g. mix-in, singleton-method)
  • Operator Overloading
  • Exception Handling
  • Iterators and Closures
  • Garbage Collection
  • Dynamic Loading of Object Files (on some architectures)
  • Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, etc.) cf. https://docs.ruby-lang.org/en/master/maintainers_md.html#label-Platform+Maintainers

How to get Ruby

For a complete list of ways to install Ruby, including using third-party tools like rvm, see:

https://www.ruby-lang.org/en/downloads/

You can download release packages and the snapshot of the repository. If you want to download whole versions of Ruby, please visit https://www.ruby-lang.org/en/downloads/releases/.

Download with Git

The mirror of the Ruby source tree can be checked out with the following command:

$ git clone https://github.com/ruby/ruby.git

There are some other branches under development. Try the following command to see the list of branches:

$ git ls-remote https://github.com/ruby/ruby.git

You may also want to use https://git.ruby-lang.org/ruby.git (actual master of Ruby source) if you are a committer.

How to build

See Building Ruby

Ruby home page

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

Documentation

Mailing list

There is a mailing list to discuss Ruby. To subscribe to this list, please send the following phrase:

join

in the mail subject (not body) to the address ruby-talk-request@ml.ruby-lang.org.

Copying

See the file COPYING.

Feedback

Questions about the Ruby language can be asked on the Ruby-Talk mailing list or on websites like https://stackoverflow.com.

Bugs should be reported at https://bugs.ruby-lang.org. Read "Reporting Issues" for more information.

Contributing

See "Contributing to Ruby", which includes setup and build instructions.

The Author

Ruby was originally designed and developed by Yukihiro Matsumoto (Matz) in 1995.

matz@ruby-lang.org

Description
Languages
Ruby 58.9%
C 29.7%
Rust 4%
C++ 3%
Makefile 2.1%
Other 2.2%