From fe53533e77df40bc48bdc287786d3e295466e2b5 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Wed, 18 Feb 2026 17:32:04 +0000 Subject: [PATCH] Force a major GC and compact before measuring RSS This will hopefully remove any variance caused by one benchmark run having just hit a GC and one not. --- harness/harness-common.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/harness/harness-common.rb b/harness/harness-common.rb index 6ee17f7e..cc39b258 100644 --- a/harness/harness-common.rb +++ b/harness/harness-common.rb @@ -146,7 +146,10 @@ def return_results(warmup_iterations, bench_iterations) yjit_stats = RubyVM::YJIT.runtime_stats if defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled? zjit_stats = RubyVM::ZJIT.stats if defined?(RubyVM::ZJIT.enabled?) && RubyVM::ZJIT.enabled? - # Collect our own peak mem usage as soon as reasonable after finishing the last iteration. + # Full GC then compact before measuring RSS so fragmentation doesn't inflate the number. + GC.start(full_mark: true, immediate_sweep: true) + GC.compact if GC.respond_to?(:compact) + rss = get_rss ruby_bench_results["rss"] = rss if maxrss = get_maxrss