From 309f450bab79a6be3ba183d702acfceb8772a949 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 16 Mar 2026 08:34:23 +0900 Subject: [PATCH] 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 --- doc/internal/gc.md | 4 +++- src/gc.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/internal/gc.md b/doc/internal/gc.md index cf221c6a5..1d355fcb3 100644 --- a/doc/internal/gc.md +++ b/doc/internal/gc.md @@ -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 diff --git a/src/gc.c b/src/gc.c index 24feb72a3..283d1dcdb 100644 --- a/src/gc.c +++ b/src/gc.c @@ -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