From 61211cf7ffe57de510dee770b3c202bebf42be65 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Wed, 4 Nov 2026 20:41:13 +0000 Subject: [PATCH] Distribute free candidates without a modulo per object add_obj_free_candidates_batch walked the whole batch once for every bucket and kept the objects where i % num_buckets == idx. Each flush of 128 candidates ran 128 * num_buckets modulo operations on the mutator thread. There is one bucket per GC worker, so the cost grew with the number of cores. In this commit we visit only the objects that belong to each bucket with skip(idx).step_by(num_buckets). Each object still goes to bucket i % num_buckets, and each flush visits every object once. On a c6i.metal with 64 GC workers, the ruby-bench headline geomean speedup with YJIT is 1.15x. With 1 GC worker there is no change. --- gc/mmtk/src/weak_proc.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gc/mmtk/src/weak_proc.rs b/gc/mmtk/src/weak_proc.rs index 2592490..0dab035 100644 --- a/gc/mmtk/src/weak_proc.rs +++ b/gc/mmtk/src/weak_proc.rs @@ -61,10 +61,8 @@ impl WeakProcessor { let num_buckets = self.parallel_obj_free_candidates.len(); for idx in 0..num_buckets { let mut bucket = self.parallel_obj_free_candidates[idx].lock().unwrap(); - for (i, &obj) in objects.iter().enumerate() { - if i % num_buckets == idx { - bucket.push(obj); - } + for &obj in objects.iter().skip(idx).step_by(num_buckets) { + bucket.push(obj); } } } else {