Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Garbage Collection Heap Slot size

So, ruby enterprise documentation states that all the values in the GC settings are defined in slots: http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning

(e.g. RUBY_HEAP_MIN_SLOTS)

We fine-tuned our app's min slot size and increment for the best performance by trial and error (we have enough machines to get a good idea how different values affect the number of malloc calls and Full GCs).

But something has been bugging me for a while: How big is 1 slot in bytes?

like image 518
glebm Avatar asked Oct 04 '10 00:10

glebm


People also ask

How does garbage collection work in Ruby?

The Ruby Garbage Collector module is an interface to Ruby's mark and sweep garbage collection mechanism. While it runs automatically in the background when needed, the GC module lets you call the GC manually whenever required and gain insights into how garbage collection cycles are running.

Does Ruby use garbage collection?

Many modern programming languages manage memory for you, and Ruby is no different. Ruby manages memory usage using a garbage collector (also called gc).

How does Ruby manage memory?

For Dynamic Memory allocation, the Ruby program uses Heap memory and the basic unit of the heap is a slot. Here, each slot occupies a value which is known as RVALUE. This RVALUE comprises 40 bytes and a container for objects of all types (Array, String, Class).

Does Ruby support automatic memory management?

Ruby, like most other modern, high-level programming languages, doesn't force you to manage memory. This feature is called garbage collection, or GC, and you get it for free in Ruby.


1 Answers

From Ruby source:

 *  sizeof(RVALUE) is
 *  20 if 32-bit, double is 4-byte aligned
 *  24 if 32-bit, double is 8-byte aligned
 *  40 if 64-bit
like image 150
Sam Saffron Avatar answered Nov 15 '22 10:11

Sam Saffron