eileencodes e8ae922b62 Add a cache for class variables
This change implements a cache for class variables. Previously there was
no cache for cvars. Cvar access is slow due to needing to travel all the
way up th ancestor tree before returning the cvar value. The deeper the
ancestor tree the slower cvar access will be.

The benefits of the cache are more visible with a higher number of
included modules due to the way Ruby looks up class variables. The
benchmark here includes 26 modules and shows with the cache, this branch
is 6.5x faster when accessing class variables.

```
compare-ruby: ruby 3.1.0dev (2021-03-15T06:22:34Z master 9e5105ca45) [x86_64-darwin19]
built-ruby: ruby 3.1.0dev (2021-03-15T12:12:44Z add-cache-for-clas.. c6be0093ae) [x86_64-darwin19]

|         |compare-ruby|built-ruby|
|:--------|-----------:|---------:|
|vm_cvar  |      5.681M|   36.980M|
|         |           -|     6.51x|
```

Benchmark.ips calling `ActiveRecord::Base.logger` from within a Rails
application. ActiveRecord::Base.logger has 71 ancestors. The more
ancestors a tree has, the more clear the speed increase. IE if Base had
only one ancestor we'd see no improvement. This benchmark is run on a
vanilla Rails application.

Benchmark code:

```ruby
require "benchmark/ips"
require_relative "config/environment"

Benchmark.ips do |x|
  x.report "logger" do
    ActiveRecord::Base.logger
  end
end
```

Ruby 3.0 master / Rails 6.1:

```
Warming up --------------------------------------
              logger   155.251k i/100ms
Calculating -------------------------------------
```

Ruby 3.0 with cvar cache /  Rails 6.1:

```
Warming up --------------------------------------
              logger     1.546M i/100ms
Calculating -------------------------------------
              logger     14.857M (± 4.8%) i/s -     74.198M in   5.006202s
```

Lastly we ran a benchmark to demonstate the difference between master
and our cache when the number of modules increases. This benchmark
measures 1 ancestor, 30 ancestors, and 100 ancestors.

Ruby 3.0 master:

```
Warming up --------------------------------------
            1 module     1.231M i/100ms
          30 modules   432.020k i/100ms
         100 modules   145.399k i/100ms
Calculating -------------------------------------
            1 module     12.210M (± 2.1%) i/s -     61.553M in   5.043400s
          30 modules      4.354M (± 2.7%) i/s -     22.033M in   5.063839s
         100 modules      1.434M (± 2.9%) i/s -      7.270M in   5.072531s

Comparison:
            1 module: 12209958.3 i/s
          30 modules:  4354217.8 i/s - 2.80x  (± 0.00) slower
         100 modules:  1434447.3 i/s - 8.51x  (± 0.00) slower
```

Ruby 3.0 with cvar cache:

```
Warming up --------------------------------------
            1 module     1.641M i/100ms
          30 modules     1.655M i/100ms
         100 modules     1.620M i/100ms
Calculating -------------------------------------
            1 module     16.279M (± 3.8%) i/s -     82.038M in   5.046923s
          30 modules     15.891M (± 3.9%) i/s -     79.459M in   5.007958s
         100 modules     16.087M (± 3.6%) i/s -     81.005M in   5.041931s

Comparison:
            1 module: 16279458.0 i/s
         100 modules: 16087484.6 i/s - same-ish: difference falls within error
          30 modules: 15891406.2 i/s - same-ish: difference falls within error
```

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-05-11 12:04:27 -07:00
2021-05-10 21:33:56 -07:00
2021-05-11 12:04:27 -07:00
2021-04-25 19:46:00 +12:00
2021-04-10 11:57:45 +09:00
2021-05-07 15:14:08 -05:00
2021-04-13 14:30:21 +09:00
2021-05-10 19:19:35 +09:00
2021-04-22 20:55:52 +09:00
2021-05-11 12:04:27 -07:00
2021-05-11 12:04:27 -07:00
2020-09-28 18:53:25 +09:00
2021-05-10 15:59:23 +09:00
2021-05-11 11:29:41 +09:00
2021-05-04 14:56:55 +02:00
2021-05-11 20:08:03 +09:00
2021-05-04 20:38:25 -04:00
2021-01-15 12:29:39 +09:00
2020-11-24 08:38:06 +09:00
2021-03-17 18:52:53 +09:00
2021-03-22 22:51:15 +09:00
2021-05-08 09:41:08 -04:00
2021-05-04 14:56:55 +02:00
2021-05-04 14:56:55 +02:00
2021-05-11 12:04:27 -07:00
2021-05-11 12:04:27 -07:00
2021-05-11 12:04:27 -07:00
2021-05-10 15:59:23 +09:00
2021-04-26 10:07:41 +09:00
2021-05-07 15:14:08 -05:00
2021-03-12 19:28:17 +09:00
2021-03-24 20:13:55 +09:00
2021-05-10 14:00:36 -05:00
2021-04-30 17:13:04 -07:00
2021-05-04 14:56:55 +02:00
2021-05-07 11:22:32 -05:00
2021-05-11 12:04:27 -07:00
2020-12-17 13:26:53 -08:00
2020-12-02 13:32:43 +09:00
GPL
2021-05-11 12:04:27 -07:00
2021-05-11 12:04:27 -07:00
2021-05-10 15:59:23 +09:00
2020-10-03 00:45:06 +09:00
2021-05-10 15:59:23 +09:00
2021-03-20 21:00:29 +09:00
2021-05-08 14:45:30 -07:00
2021-05-04 14:56:55 +02:00
2020-12-21 21:16:39 -08:00
2021-01-05 02:27:58 +09:00
2021-01-05 02:27:58 +09:00
2021-03-04 11:40:43 +09:00
2021-04-27 17:05:19 +09:00
2020-08-31 18:08:57 +09:00
2020-12-24 01:59:36 +09:00
2021-05-04 14:56:55 +02:00
2021-04-26 10:07:41 +09:00
2021-04-26 10:07:41 +09:00
2021-05-04 20:38:03 -04:00
2021-03-17 23:55:03 +09:00
2021-05-04 14:56:55 +02:00
2021-03-30 18:38:42 +13:00
2021-05-04 20:38:03 -04:00
2021-04-13 12:05:31 +09:00
2021-03-05 16:33:29 +09:00
2020-11-18 03:52:41 +09:00
2021-04-29 19:58:15 -07:00
2021-05-08 11:40:20 +09:00
2021-04-26 10:07:41 +09:00
2020-12-07 08:28:36 +09:00
2020-12-07 08:28:36 +09:00
2021-05-03 11:17:14 +12:00
2021-05-11 12:04:27 -07:00
2021-05-12 01:05:27 +09:00
2021-01-08 14:39:05 +09:00
2021-05-11 12:04:27 -07:00
2021-05-04 14:56:55 +02:00
2020-12-26 09:39:53 +09:00
2021-02-09 08:41:06 +09:00
2021-05-11 12:04:27 -07:00

Build status Actions Status: macOS Actions Status: MinGW Actions Status: MJIT Actions Status: Ubuntu Actions Status: Windows

What's 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/contributing.rdoc#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/

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.

Subversion

Stable branches for older Ruby versions can be checked out with also the following command:

$ svn co https://svn.ruby-lang.org/repos/ruby/branches/ruby_2_6/ ruby

Try the following command to see the list of branches:

$ svn ls https://svn.ruby-lang.org/repos/ruby/branches/

Ruby home page

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

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.

How to compile and install

  1. If you want to use Microsoft Visual C++ to compile Ruby, read win32/README.win32 instead of this document.

  2. Run ./autogen.sh to generate configure, when you build the source checked out from the Git repository.

  3. Run ./configure, which will generate config.h and Makefile.

    Some C compiler flags may be added by default depending on your environment. Specify optflags=.. and warnflags=.. as necessary to override them.

  4. Edit include/ruby/defines.h if you need. Usually this step will not be needed.

  5. Optional: Remove comment mark(#) before the module names from ext/Setup.

    This step is only necessary if you want to link modules statically.

    If you don't want to compile dynamic extensions (probably on architectures which do not allow dynamic loading), remove comment mark from the line "#option nodynamic" in ext/Setup.

    Usually this step will not be needed.

  6. Run make.

    • On Mac, set RUBY_CODESIGN environment variable with a signing identity. It uses the identity to sign ruby binary. See also codesign(1).
  7. Optionally, run 'make check' to check whether the compiled Ruby interpreter works well. If you see the message "check succeeded", your Ruby works as it should (hopefully).

  8. Run 'make install'.

    This command will create the following directories and install files into them.

    • ${DESTDIR}${prefix}/bin
    • ${DESTDIR}${prefix}/include/ruby-${MAJOR}.${MINOR}.${TEENY}
    • ${DESTDIR}${prefix}/include/ruby-${MAJOR}.${MINOR}.${TEENY}/${PLATFORM}
    • ${DESTDIR}${prefix}/lib
    • ${DESTDIR}${prefix}/lib/ruby
    • ${DESTDIR}${prefix}/lib/ruby/${MAJOR}.${MINOR}.${TEENY}
    • ${DESTDIR}${prefix}/lib/ruby/${MAJOR}.${MINOR}.${TEENY}/${PLATFORM}
    • ${DESTDIR}${prefix}/lib/ruby/site_ruby
    • ${DESTDIR}${prefix}/lib/ruby/site_ruby/${MAJOR}.${MINOR}.${TEENY}
    • ${DESTDIR}${prefix}/lib/ruby/site_ruby/${MAJOR}.${MINOR}.${TEENY}/${PLATFORM}
    • ${DESTDIR}${prefix}/lib/ruby/vendor_ruby
    • ${DESTDIR}${prefix}/lib/ruby/vendor_ruby/${MAJOR}.${MINOR}.${TEENY}
    • ${DESTDIR}${prefix}/lib/ruby/vendor_ruby/${MAJOR}.${MINOR}.${TEENY}/${PLATFORM}
    • ${DESTDIR}${prefix}/lib/ruby/gems/${MAJOR}.${MINOR}.${TEENY}
    • ${DESTDIR}${prefix}/share/man/man1
    • ${DESTDIR}${prefix}/share/ri/${MAJOR}.${MINOR}.${TEENY}/system

    If Ruby's API version is 'x.y.z', the ${MAJOR} is 'x', the ${MINOR} is 'y', and the ${TEENY} is 'z'.

    NOTE: teeny of the API version may be different from one of Ruby's program version

    You may have to be a super user to install Ruby.

If you fail to compile Ruby, please send the detailed error report with the error log and machine/OS type, to help others.

Some extension libraries may not get compiled because of lack of necessary external libraries and/or headers, then you will need to run 'make distclean-ext' to remove old configuration after installing them in such case.

Copying

See the file COPYING.

Feedback

Questions about the Ruby language can be asked on the Ruby-Talk mailing list (https://www.ruby-lang.org/en/community/mailing-lists) or on websites like (https://stackoverflow.com).

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

Contributing

See the file CONTRIBUTING.md

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.5%
Rust 6.1%
C++ 2.9%
Yacc 0.9%
Other 1.6%