Skip to content

Instantly share code, notes, and snippets.

@zekefast
Last active May 23, 2018 09:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zekefast/5253983 to your computer and use it in GitHub Desktop.
Save zekefast/5253983 to your computer and use it in GitHub Desktop.
Tune Ruby garbage collector to improve test speed. This is also lead to enormous memory usage. More information about GC parameters tuning could be found in follow articles: [Chapter 4.2: "Garbage collector performance tuning" in Ruby Enterprise Edition (1.8.7)](http://www.rubyenterpriseedition.com/documentation.html) ["Ruby’s GC Configuration" …
# Allows to run GC less frequently which is significantly speed up specs running.
# Look for more detailed description in follow articles:
# - http://www.rubyenterpriseedition.com/documentation.html (Chapter 4.2: "Garbage collector performance tuning")
# - http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
# Initial number of heap slots. It also represents the minimum number of slots, at all times (default: 10000)
#export RUBY_HEAP_MIN_SLOTS=1000000 # for Rubies < 2.1
export RUBY_GC_HEAP_INIT_SLOTS=1000000 # for Rubies >= 2.1.0
# The number of new slots to allocate when all initial slots are used (default: 10000)
export RUBY_HEAP_SLOTS_INCREMENT=1000000
# Next time Ruby needs new heap slots it will use a multiplicator, defined by this environment variable’s value
# (default: 1.8, meaning it will allocate 18000 new slots if default settings are in use)
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
# The number of C data structures that can be allocated before triggering the garbage collector.
# This one is very important since the default value makes the GC run when there are still empty
# heap slots because Rails allocates and deallocates a lot of data (default: 8000000)
export RUBY_GC_MALLOC_LIMIT=100000000
# The number of free slots that should be present after GC finishes running.
# If there are fewer slots than those defined it will allocate new ones according
# to RUBY_HEAP_SLOTS_INCREMENT and RUBY_HEAP_SLOTS_GROWTH_FACTOR parameters (default: 4096)
export RUBY_HEAP_FREE_MIN=500000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment