software and other stuff.

Improving the Ruby GC

overview

This page details some changes to the ruby garbage collector which seem to afford a 25% reduction in maximum heap memory usage, and nearly double the amount of heap space ruby's is able to reclaim. This comes at the cost of a 2% performance hit. More to come, stay tuned.

patch

The latest patch to ruby 1.8.6 is available here.

summary of changes

testing strategy

To test changes, I'm comparing the performance of a handful of tests (most contributed by Hugh Sasse, many thanks!). Ruby 1.8.6 unpatched is run over these tests, then compared against the performance of ruby 1.8.6 with my patch. In order to get "maximum heap size", "current heap size", and "nmber of gc passes", a GC.heap_info function has been hacked in to both.

NOTE: When referring to heap size, we're really talking about the amount of memory dedicated to ruby heaps, not the total heap usage of the ruby process.

finally, all tests are performed on a macbook dual core with 2 gigs of RAM. We use wallclock time, but I've ensured an idle machine and rerun tests to verify that system load doesn't significantly affect results.

data

test before after difference
test timegc passes max mem final mem timegc passes max mem final mem timegc passes % max mem % final mem %
cases/weak_hashes_read.rb 0.459784844739804473980 0.448108925702402570240 97% 112% 57% 57%
cases/create_hashes_yaml.rb 25.91340875273000608253120 26.4338737518012160614400 102% 100% 65% 7%
cases/create_hashes.rb 0.13459641208000560000 0.1422046107724875776 105% 150% 89% 13%
cases/arrays_read_yaml.rb 0.760341444739804473980 0.7527751332788483278848 99% 92% 73% 73%
cases/ostruct_read.rb 2.64286191505544015055440 2.8656752287818248781824 108% 115% 58% 58%
cases/create_ostructs_yaml.rb 13.673743552729978015055440 14.47161157156160009125888 105% 103% 57% 60%
cases/classes_read_yaml.rb 0.8254551344739404473940 0.849941341512964149248 102% 100% 92% 92%
cases/create_weak_hashes2.rb 0.497352744739404473940 0.512148926439682490368 102% 128% 59% 55%
cases/create_arrays_yaml.rb 9.00269243150556608253140 9.1689354498590722252800 101% 102% 65% 27%
cases/create_arrays.rb 0.17099942374420560000 0.179486191283275776 104% 150% 80% 13%
cases/growarray.rb 1.9331199200000200000 2.116156910240075776 109% 100% 51% 37%
cases/arrays_read.rb 0.08932642374460560000 0.0922445167936073728 103% 125% 70% 13%
cases/hashes_read_yaml.rb 1.9820082344739204473920 1.9084582045322244532224 96% 86% 101% 101%
cases/plist.rb 4.926278231505576015055760 4.773025181273446410463232 96% 78% 84% 69%
cases/create_ostructs.rb 3.076644221505566011276480 3.28431524880025692160 106% 109% 58% 0%
cases/create_weak_hashes.rb 1.2055061744739604473960 1.1317341452531204933632 93% 82% 117% 110%
cases/classes_read.rb 0.056913312080001208000 0.0629345919552919552 110% 166% 76% 76%
cases/shrinkarray.rb 1.9320019200000200000 2.122906910035277824 109% 100% 50% 38%
cases/ostruct_read_yaml.rb 1.1427352023744002374400 1.1141331731784963178496 97% 85% 133% 133%
cases/hashes_read.rb 0.0522312080001208000 0.0523934876544876544 100% 133% 72% 72%
102% 110% 75% 55%

feedback

send perf feedback to lloyd at hilaiel d0t com.