Skip to content

Instantly share code, notes, and snippets.

@briankung
Created September 27, 2013 20:39
Show Gist options
  • Save briankung/6734829 to your computer and use it in GitHub Desktop.
Save briankung/6734829 to your computer and use it in GitHub Desktop.
Some notes on tweaking MRI Ruby's Garbage Collector

Tweaking MRI Ruby's Garbage Collector

I came across Fred Wu's post endorsing tweaking your MRI Ruby garbage collection settings for great justice. The results in the post and comments indicated ~33% speedup. Intrigued, I started looking into it more and found more in-depth explanations for the magic by Dennis Taylor and on StackOverflow.

After local testing that put our numbers in line with Fred Wu and readers', I tried it out on our test environment in Jenkins. Preliminary results are a 42.45% speedup on an M1 Large Amazon EC2 instance (7.5 GiB).

Awesome.

@briankung
Copy link
Author

Without tweaks:

  • Finished in 4 minutes 26.08 seconds
  • Finished in 4 minutes 13.66 seconds

Baseline of about 4:15-4:30, based on prior experience.

With tweaks:

  • Finished in 2 minutes 41.51 seconds
  • Finished in 2 minutes 35.94 seconds
  • Finished in 2 minutes 35.17 seconds
  • Finished in 2 minutes 42.87 seconds
  • Finished in 2 minutes 43.85 seconds
  • Finished in 2 minutes 42.25 seconds

A significant improvement, pretty much in line with results on Fred Wu's post.

With tweaks and a ridiculous Ruby GC Malloc Limit (1,000,000,000):

  • Finished in 2 minutes 38.49 seconds
  • Finished in 2 minutes 38.26 seconds

I was testing Dennis Taylor's post on Goclio, but it seemed to negatively affect the speed. Note that at the time, the tweaked tests were running in around 2 minutes and 35 seconds.

With RUBY_HEAP_FREE_MIN instead of RUBY_FREE_MIN:

  • Finished in 2 minutes 44.33 seconds
  • Finished in 2 minutes 50.64 seconds

I was messing around to see whether RUBY_HEAP_~ was a valid variable to use. According to the StackOverflow post, RUBY_FREE_MIN is the correct variable name.

With RUBY_MIN_SLOTS:

  • Finished in 2 minutes 41.49 seconds
  • Finished in 2 minutes 44.3 seconds
  • Finished in 2 minutes 42.62 seconds

While this was left out of Fred Wu's post, it seemed not to affect test speed.

I understand that these tests are not statistically rigorous. I'm okay with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment