Daniel Colson e69b91fae4 Introduce BOP_CMP for optimized comparison
Prior to this commit the `OPTIMIZED_CMP` macro relied on a method lookup
to determine whether `<=>` was overridden. The result of the lookup was
cached, but only for the duration of the specific method that
initialized the cmp_opt_data cache structure.

With this method lookup, `[x,y].max` is slower than doing `x > y ?
x : y` even though there's an optimized instruction for "new array max".
(John noticed somebody a proposed micro-optimization based on this fact
in https://github.com/mastodon/mastodon/pull/19903.)

```rb
a, b = 1, 2
Benchmark.ips do |bm|
  bm.report('conditional') { a > b ? a : b }
  bm.report('method') { [a, b].max }
  bm.compare!
end
```

Before:

```
Comparison:
         conditional: 22603733.2 i/s
              method: 19820412.7 i/s - 1.14x  (± 0.00) slower
```

This commit replaces the method lookup with a new CMP basic op, which
gives the examples above equivalent performance.

After:

```
Comparison:
              method: 24022466.5 i/s
         conditional: 23851094.2 i/s - same-ish: difference falls within
error
```

Relevant benchmarks show an improvement to Array#max and Array#min when
not using the optimized newarray_max instruction as well. They are
noticeably faster for small arrays with the relevant types, and the same
or maybe a touch faster on larger arrays.

```
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_min
$ make benchmark COMPARE_RUBY=<master@5958c305> ITEM=array_max
```

The benchmarks added in this commit also look generally improved.

Co-authored-by: John Hawthorn <jhawthorn@github.com>
2022-12-06 12:37:23 -08:00
2022-12-06 13:50:14 +09:00
2022-12-05 14:33:16 -08:00
2022-12-03 02:23:28 +09:00
2022-12-05 17:09:49 +09:00
2022-12-05 17:09:49 +09:00
2022-11-25 19:42:47 +09:00
2022-12-01 15:37:15 -08:00
2022-12-02 01:19:55 +09:00
2022-12-02 12:24:17 -05:00
2022-11-13 14:00:30 -08:00
2022-12-02 01:19:55 +09:00
2022-12-02 01:19:55 +09:00
2022-11-20 21:07:18 -08:00
GPL
2022-11-16 18:58:33 +09:00
2022-11-10 10:52:16 +09:00
2022-12-02 23:46:21 +09:00
2022-12-04 15:23:09 -05:00
2022-11-16 18:58:33 +09:00
2022-11-29 21:34:46 -08:00
2022-11-29 21:34:46 -08:00
2022-12-06 18:23:54 +09:00
2022-11-16 18:58:33 +09:00
2022-11-22 13:49:46 -08:00
2022-12-03 08:53:12 +09:00
2022-11-16 18:58:33 +09:00
2022-11-16 18:58:33 +09:00
2022-12-02 01:31:27 +09:00
2022-11-09 23:21:26 +09:00
2022-11-16 18:58:33 +09:00
2022-11-16 18:58:33 +09:00
2022-11-16 18:58:33 +09:00
2022-12-02 01:31:27 +09:00
2022-12-02 01:31:27 +09:00
2022-11-22 23:10:46 +02:00
2022-11-22 23:10:46 +02:00
2022-11-16 18:58:33 +09:00
2022-11-16 18:58:33 +09:00
2022-12-02 23:46:21 +09:00
2022-11-16 18:58:33 +09:00
2022-12-06 12:37:23 -08:00
2022-11-16 18:58:33 +09:00
2022-11-16 18:58:33 +09:00
2022-12-02 23:46:21 +09:00
2022-11-16 18:58:33 +09:00

Actions Status: MinGW Actions Status: MJIT 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://github.com/ruby/ruby/blob/master/doc/maintainers.rdoc#label-Platform+Maintainers

How to get Ruby with Git

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

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

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:

subscribe

in the mail body (not subject) to the address ruby-talk-request@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%