
4/6/2023
What this post added
This post details the technical steps taken to improve Ruby garbage collection (GC) performance in Shopify's monolith. It outlines the problem of GC-induced latency, explains Ruby's generational, incremental, mark-and-sweep GC, and identifies the primary triggers for major GC marks: `:oldmalloc` and `:nofree`. For `:oldmalloc`, the solution involved setting a very high `RUBY_GC_OLDMALLOC_LIMIT` to effectively disable this heuristic. For `:nofree`, the issue was addressed by significantly increasing `RUBY_GC_HEAP_INIT_SLOTS` and, due to Ruby 3.2's variable width allocation, implementing a custom pre-allocation strategy for different slot sizes via environment variables and a temporary `config/boot.rb` hack, which was later upstreamed as a Ruby feature. The post also includes detailed metrics and graphs showing the impact of these changes on GC latency.