Takeaways

Ruby GC is not a black box. Once you understand how it works, you can either change your code to put less strain on it, or you can tune GC up for better performance. Here’s what you need to keep in mind:

  • Ruby allocates objects on a dedicated heap space, which it manages itself.

  • Each object has the fixed amount of storage (40 bytes on 64-bit computers). If the object needs more memory, it allocates that on the operating system heap.

  • Ruby runs GC when it decides that it allocated too many objects or its objects allocated too much memory. Correspondingly, there are two criteria for this decision. First, Ruby heap space doesn’t have enough free slots. Second, the current memory allocation (malloc) limit has been exceeded.

  • You can tweak most GC parameters for optimal performance. In practice, however, it makes sense to change only memory allocation limits. If you use Ruby 2.0 or earlier, you must increase RUBY_GC_MALLOC_LIMIT at least twice. If you use Ruby 2.1 and later, you may not need to change anything. In any case, make sure you measure the performance after the change.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.197.213