Skip to content

Distribute free candidates without a modulo per object - #140

Merged
eightbitraptor merged 1 commit into
mainfrom
mvh-weak-proc-stride
Nov 6, 2026
Merged

eightbitraptor merged 1 commit into
mainfrom
mvh-weak-proc-stride

Conversation

@eightbitraptor

Copy link
Copy Markdown
Member

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.

This has a notable effect on headline benchmarks:

parent: ruby 4.1.0dev (2026-11-04T15:37:16Z HEAD 5888302d4f) +YJIT +PRISM +GC[mmtk] [x86_64-linux]
commit: ruby 4.1.0dev (2026-11-04T15:37:16Z HEAD 5888302d4f) +YJIT +PRISM +GC[mmtk] [x86_64-linux]
ruby-bench: 73918b2fc1a84702fea63e06f64d179751d69df4

--------------  -------------  -------------  --------------  -------------
bench             parent (ms)    commit (ms)  commit 1st itr  parent/commit
activerecord     209.4 ± 2.8%   178.5 ± 2.7%           1.132          1.173
chunky-png       441.8 ± 0.8%   432.5 ± 1.0%           1.017          1.022
erubi-rails     1364.2 ± 0.4%  1048.6 ± 0.7%           1.269          1.301
hexapdf         1762.8 ± 3.4%  1576.5 ± 3.2%           1.054          1.118
liquid-c          66.6 ± 5.7%    57.3 ± 6.7%           1.090          1.162
liquid-compile    64.3 ± 9.2%   51.6 ± 10.8%           1.119          1.245
liquid-il        221.1 ± 1.5%   200.2 ± 1.3%           1.064          1.105
liquid-render     94.3 ± 3.9%    75.8 ± 4.4%           1.119          1.244
lobsters         854.2 ± 1.7%   792.6 ± 1.7%           1.038          1.078
mail             164.2 ± 2.3%   130.2 ± 2.7%           1.079          1.261
psych-load      1925.3 ± 1.1%  1772.2 ± 1.6%           1.063          1.086
railsbench      1702.2 ± 1.0%  1514.8 ± 1.0%           1.081          1.124
rubocop          130.5 ± 9.9%   114.0 ± 9.4%           1.009          1.144
ruby-lsp         155.4 ± 5.6%   138.9 ± 3.7%           1.074          1.118
sequel            87.1 ± 2.3%    71.4 ± 3.2%           1.071          1.220
shipit          1181.5 ± 2.1%  1077.1 ± 2.7%           1.058          1.097
--------------  -------------  -------------  --------------  -------------

Legend:
- commit 1st itr: ratio of parent/commit time for the first iteration.
- parent/commit: ratio of parent/commit time. Higher is better for commit. Above 1 represents a speedup.

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.
@eightbitraptor
eightbitraptor merged commit 477de42 into main Nov 6, 2026
29 of 30 checks passed
@eightbitraptor
eightbitraptor deleted the mvh-weak-proc-stride branch November 6, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant