Which method of garbage collection would most suit Ruby?
I’ve implemented a mark-and-sweep GC with incremental sweep so far. The
incremental sweep algorithm makes GC times less intrusive and could possibly
be added to Ruby without too much trouble.
Some features of the collector:
- Memory is reserved in 4k blocks aligned on a 4k boundary.
- Each block stores objects of a fixed size.
- Allocation is either sequential when filling a new block or resuses
linked garbage fragments within the block. Either way, allocation is very
- Each block stores mark bits and live bits - this information is not
stored with the object.
- Valid ptr checks are really fast using a similar technique to the one in
the Boehm-Demers-Weiser collector.
- Stack is used for conservative collection although unlike the
Boehm-Demers-Weiser collector, objects know how to collect themselves.
However, to make things really fast I think I need to make my collector
Normally, generational collectors are based on copy collection in the young
generation and mark-and-sweep in the older generations. A notable exception
is the train algorithm.
I can see that having a copy collector for the young generation is a win for
functional languages such as ML/OCaml where 90%+ of the objects don’t
survive infancy and so not much is actually copied. This may not be the
case in Ruby where more objects may survive infancy and so result in
increased copying overheads.
Therefore, I’ve decided to keep the young generation mark-and-sweep.
For the old generations I like the sound of the train algorithm because of
it’s incremental and ordering nature. The main problem is that I’d like to
avoid hardware write barriers for the remembered sets.
Anybody out there with any views on this?
Matz, did you have any ideas on the GC for Rite?