gc.c: use actual work done for debt repayment in incremental step

Decrement gc_debt by the actual number of objects processed
instead of the fixed GC_STEP_SIZE. This makes step_ratio
directly affect debt repayment: larger steps repay more debt,
naturally reducing GC invocation frequency.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-03-16 08:34:23 +09:00
parent 851da984b4
commit 309f450bab
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -131,7 +131,9 @@ limit = (GC_STEP_SIZE / 100) * step_ratio
```
With default `step_ratio = 200` and `GC_STEP_SIZE = 1024`, the
limit is 2048 objects per step.
limit is 2048 objects per step. After each step, `gc_debt` is
decremented by the actual number of objects processed, so larger
steps repay more debt.
When the gray stack is exhausted, the final marking phase re-marks
the arena and global variables to catch objects created during
+1 -1
View File
@@ -1332,7 +1332,7 @@ incremental_gc_step(mrb_state *mrb, mrb_gc *gc)
break;
}
gc->gc_debt -= (mrb_int)GC_STEP_SIZE;
gc->gc_debt -= (mrb_int)result;
}
static void