@@ -1046,8 +1046,18 @@ total_final_slots_count(rb_objspace_t *objspace)
10461046#define is_full_marking (objspace ) ((objspace)->flags.during_minor_gc == FALSE)
10471047#define is_incremental_marking (objspace ) ((objspace)->flags.during_incremental_marking != FALSE)
10481048#define will_be_incremental_marking (objspace ) ((objspace)->rgengc.need_major_gc != GPR_FLAG_NONE)
1049- #define GC_INCREMENTAL_SWEEP_SLOT_COUNT 2048
1050- #define GC_INCREMENTAL_SWEEP_POOL_SLOT_COUNT 1024
1049+ /*
1050+ * Byte budget for incremental sweep steps. Each step sweeps at most
1051+ * this many bytes worth of slots before yielding. The effective slot
1052+ * count per step is GC_INCREMENTAL_SWEEP_BYTES / heap->slot_size,
1053+ * so larger slot pools (which are less heavily used) naturally get
1054+ * fewer slots swept per step.
1055+ *
1056+ * Baseline: 2048 slots * RVALUE_SLOT_SIZE = 2048 * 40 = 81920 bytes,
1057+ * preserving the historical behavior for the smallest heap.
1058+ */
1059+ #define GC_INCREMENTAL_SWEEP_BYTES (2048 * RVALUE_SLOT_SIZE)
1060+ #define GC_INCREMENTAL_SWEEP_POOL_BYTES (1024 * RVALUE_SLOT_SIZE)
10511061#define is_lazy_sweeping (objspace ) (GC_ENABLE_LAZY_SWEEP && has_sweeping_pages(objspace))
10521062/* In lazy sweeping or the previous incremental marking finished and did not yield a free page. */
10531063#define needs_continue_sweeping (objspace , heap ) \
@@ -3877,6 +3887,8 @@ gc_sweep_step(rb_objspace_t *objspace, rb_heap_t *heap)
38773887 struct heap_page * sweep_page = heap -> sweeping_page ;
38783888 int swept_slots = 0 ;
38793889 int pooled_slots = 0 ;
3890+ int sweep_budget = GC_INCREMENTAL_SWEEP_BYTES / heap -> slot_size ;
3891+ int pool_budget = GC_INCREMENTAL_SWEEP_POOL_BYTES / heap -> slot_size ;
38803892
38813893 if (sweep_page == NULL ) return FALSE;
38823894
@@ -3922,14 +3934,14 @@ gc_sweep_step(rb_objspace_t *objspace, rb_heap_t *heap)
39223934 heap -> freed_slots += ctx .freed_slots ;
39233935 heap -> empty_slots += ctx .empty_slots ;
39243936
3925- if (pooled_slots < GC_INCREMENTAL_SWEEP_POOL_SLOT_COUNT ) {
3937+ if (pooled_slots < pool_budget ) {
39263938 heap_add_poolpage (objspace , heap , sweep_page );
39273939 pooled_slots += free_slots ;
39283940 }
39293941 else {
39303942 heap_add_freepage (heap , sweep_page );
39313943 swept_slots += free_slots ;
3932- if (swept_slots > GC_INCREMENTAL_SWEEP_SLOT_COUNT ) {
3944+ if (swept_slots > sweep_budget ) {
39333945 break ;
39343946 }
39353947 }
0 commit comments