Garbage Collection and the Ruby Heap
The talk will start out with a brief overview of stacks vs heaps, and various garbage collection algorithms. We’ll explain the details of the MRI implementation of ruby heap (10k initial slots, grows by 1.8x each time, linked list of free slots) and garbage collector (stop the world mark-and-sweep collector, scans the C stack, triggered by 8mb malloc_limit and rb_newobj).
After explaining the basics, we’ll focus on specific examples and show off a variety of tools and patches:
- understanding and tuning the GC: ObjectSpace statistics, RAILSBENCH
- finding reference leaks in ruby: BleakHouse, GC.dump_heap
- reducing memory usage and overhead: Copy-on-Write GC / REE, tcmalloc
- finding C extension memory leaks: valgrind, google-perftools heap profiler
We’ll also highlight common tricks for improving the performance of ruby code running under MRI by reducing the memory overhead:
- store commonly used strings in constants instead of using them inline
- use symbols instead of strings
- invoke GC after large allocations
- disable GC during time sensitive operations
Finally we’ll look ahead to ruby 1.9 and jruby and talk about how they fix some of these issues in MRI.
Aman Gupta
GitHub
Aman is a serial entrepreneur, ruby hacker and a recent winner of a Ruby Heroes award. He currently maintains the EventMachine project and various other gems that help build high-performance distributed and asynchronous systems in ruby, including em-mysql, em-spec, jsSocket and amqp.
Most recently, Aman has been hacking on performance improvements to MRI, releasing several patches to ruby and perftools.rb, a sampling profiler for ruby code based on google-perftools.
Joe Damato
Boundary
Joe Damato is a hacker who focuses on the low level implications of Ruby including I/O, performance, testing, and scaling. He maintains a blog (http://timetobleed.com) where he releases code, patches to the Ruby interpreter, and his thoughts about low level systems programming. He has submitted a few patches to Ruby core, the most interesting of which is a bug-fix to the threading implementation in Ruby 1.8 and a Fibers implementation for Ruby 1.8 that he worked on with Aman Gupta. He also added libdl support to ltrace to allow tracing library functions which are linked at runtime (such as Ruby gems).
Comments on this page are now closed.

















Comments
This was the first talk I attended that addressed topics at a super-technical level, and it was very interesting and very well presented. Also, memprof is an amazing tool!
Very engaging for the depth of technical detail you were going through, and appreciated that you shared your REE config data too.
your hard work shone through this whole talk; I appreciated the advanced level discussion that was still accessible to me, an intermediate-level Rubyist and a novice to OS programming
great talk!! awesome tools, can’t wait to try them!
Thank you
great talk