Peter Zhu 782d959f67 Implement moving Immix in MMTk
This commit implements moving Immix in MMTk, which allows objects to move
in the GC.

The performance of this implementation is not yet amazing. It is very
similar to non-moving Immix in many of them and slightly slower in others.
The benchmark results is shown below.

    --------------  -----------------  ----------  ---------
    bench           Moving Immix (ms)  stddev (%)  RSS (MiB)
    activerecord    241.9              0.5         86.6
    chunky-png      447.8              0.8         74.9
    erubi-rails     1183.9             0.8         136.1
    hexapdf         1607.9             2.6         402.3
    liquid-c        45.4               6.7         44.9
    liquid-compile  44.1               9.3         53.0
    liquid-render   105.4              4.5         55.9
    lobsters        650.1              9.7         418.4
    mail            115.4              2.1         64.4
    psych-load      1656.8             0.8         43.6
    railsbench      1653.5             1.3         149.8
    rubocop         127.0              15.6        142.1
    ruby-lsp        130.7              10.5        99.4
    sequel          52.8               7.2         45.6
    shipit          1187.0             3.9         311.0
    --------------  -----------------  ----------  ---------

    --------------  ---------------------  ----------  ---------
    bench           Non-moving Immix (ms)  stddev (%)  RSS (MiB)
    activerecord    218.9                  2.7         86.1
    chunky-png      464.6                  0.8         66.7
    erubi-rails     1119.0                 4.3         132.7
    hexapdf         1539.8                 1.8         425.2
    liquid-c        40.6                   6.9         45.2
    liquid-compile  40.6                   8.1         52.9
    liquid-render   99.3                   2.3         48.3
    mail            107.4                  5.3         65.4
    psych-load      1535.6                 1.0         39.5
    railsbench      1565.6                 1.1         149.6
    rubocop         122.5                  14.3        146.7
    ruby-lsp        128.4                  10.7        106.4
    sequel          44.1                   4.0         45.7
    shipit          1154.5                 2.7         358.5
    --------------  ---------------------  ----------  ---------
2025-12-29 09:03:31 -05:00
..
2025-12-29 09:03:31 -05:00
2025-12-29 09:03:31 -05:00
2025-01-14 10:21:57 -05:00
2025-12-29 09:03:31 -05:00
2025-12-29 09:03:31 -05:00

Ruby's Garbage Collectors

This directory contains implementations for Ruby's garbage collector (GC). The GC implementations use the Modular GC API to interact with Ruby. For more details about this API, see the Modular GC API section.

Two GC implementations are included in Ruby:

  • Default: The GC implementation that is used by default in Ruby. This GC is stable and production ready. The implementation uses a mark-sweep-compact algorithm.
  • MMTk: An experimental implementation using the MMTk framework. The code lives in the ruby/mmtk repository and is synchronized here. MMTk provides a wide variety of GC algorithms to choose from. For usage instructions and current progress, refer to the ruby/mmtk repository.

Building guide

Tip

If you are not sure how to build Ruby, follow the Building Ruby guide.

Important

Ruby's modular GC feature is experimental and subject to change. There may be bugs or performance impacts. Use at your own risk.

Building Ruby with Modular GC

  1. Configure Ruby with the --with-modular-gc=<dir> option, where dir is the directory you want to place the built GC libraries into.
  2. Build Ruby as usual.

Building GC implementations shipped with Ruby

  1. Build your desired GC implementation with make install-modular-gc MODULAR_GC=<impl>. This will build the GC implementation and place the built library into the dir specified in step 1. impl can be one of:
    • default: The default GC that Ruby ships with.
    • mmtk: The GC that uses MMTk as the back-end. See Ruby-specific details in the ruby/mmtk repository.
  2. Run your desired GC implementation by setting the RUBY_GC_LIBRARY=<lib> environment variable, where lib could be default, mmtk, or your own implementation (as long as you place it in the dir specified in step 1).

Modular GC API

Warning

The Modular GC API is experimental and subject to change without notice.

GC implementations interact with Ruby via the Modular GC API. All implementations must provide the functions in gc/gc_impl.h for Ruby to hook into. GC implementations can use any public C API in Ruby, along with additional APIs defined in gc/gc.h.

Additionally, create an extconf.rb file to build the GC library. This file must use gc/extconf_base.rb and the create_gc_makefile method.