Skip to content

Commit

Permalink
Call gc_mark_ptr directly during GC loop
Browse files Browse the repository at this point in the history
Because we always use `gc_mark_ptr` from inside Ruby's GC loop we
can optimise the call to remove the function pointer lookup inside
`reachable_objects_from`.

This still allows us to remove the conditional from gc_mark_ptr and
build marking on top of a generic object traversal approach that can be
overridden easily, but mitigates the performance penalty for the default
case.
  • Loading branch information
eightbitraptor committed Aug 15, 2023
1 parent 6b33ef1 commit cd81801
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11643,7 +11643,12 @@ static void
reachable_objects_from_callback(VALUE obj)
{
rb_ractor_t *cr = GET_RACTOR();
cr->mfd.mark_func(obj, cr->mfd.data);
if (LIKELY(!cr->mfd.mark_func)) {
gc_mark_ptr(obj, (void *)&rb_objspace);
}
else {
cr->mfd.mark_func(obj, cr->mfd.data);
}
}

void
Expand Down Expand Up @@ -13745,8 +13750,8 @@ rb_gcdebug_remove_stress_to_class(int argc, VALUE *argv, VALUE self)
void
rb_ractor_init_mfd(rb_ractor_t *r)
{
r->mfd.mark_func = gc_mark_ptr;
r->mfd.data = (void *)&rb_objspace;
r->mfd.mark_func = NULL;
r->mfd.data = NULL;
}

/*
Expand Down

0 comments on commit cd81801

Please sign in to comment.