Tune Up GC Settings

We can change some of Ruby GC parameters with environment variables. Let’s see what’s available.

Ruby 2.1, 2.2, and Later

RUBY_GC_HEAP_INIT_SLOTS

Initial number of object slots on the Ruby heap. Default value is 10000.

You might want to change this number if you know that your application will allocate lots of objects right from the start.

But on the other hand, we saw that Ruby is quite good at growing the heap space. It usually grows faster than we need. So there’s little need to change this parameter in practice.

RUBY_GC_HEAP_FREE_SLOTS

Minimum number of free slots that must be free after GC. If this condition is not met, Ruby might grow the heap space. Default value is 4096.

As we discussed in GC Triggered by ...

Get Ruby Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.