Skip to content

Commit

Permalink
Set FL_EXIVAR when we have to mutate the global object_id table
Browse files Browse the repository at this point in the history
Removing objects from the global id table is expensive.  This commit
sets FL_EXIVAR on objects that have their object id set in the global
table.  That way we know to only try removal when the flag is set.
Freeing generic ivars isn't cheap anyway, so this should be a pretty
rare case.
  • Loading branch information
tenderlove committed Apr 3, 2019
1 parent e0ec831 commit 82f3d8b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gc.c
Expand Up @@ -2258,16 +2258,18 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
}

if (FL_TEST(obj, FL_EXIVAR)) {
VALUE id;

rb_free_generic_ivar((VALUE)obj);
FL_UNSET(obj, FL_EXIVAR);
}
VALUE id;
if (st_lookup(obj_to_id_tbl, (st_data_t)obj, &id)) {

if (st_lookup(obj_to_id_tbl, (st_data_t)obj, &id)) {
#ifdef GC_COMPACT_DEBUG
fprintf(stderr, "Collecting %p -> %p\n", obj, obj_id_to_ref(id));
fprintf(stderr, "Collecting %p -> %p\n", obj, obj_id_to_ref(id));
#endif
st_delete(obj_to_id_tbl, (st_data_t *)&obj, 0);
st_delete(id_to_obj_tbl, (st_data_t *)&id, 0);
st_delete(obj_to_id_tbl, (st_data_t *)&obj, 0);
st_delete(id_to_obj_tbl, (st_data_t *)&id, 0);
}
}

#if USE_RGENGC
Expand Down Expand Up @@ -3409,6 +3411,7 @@ rb_obj_id(VALUE obj)
#endif
st_insert(obj_to_id_tbl, (st_data_t)obj, id);
st_insert(id_to_obj_tbl, (st_data_t)id, obj);
FL_SET(obj, FL_EXIVAR);
return id;
}
}
Expand Down

0 comments on commit 82f3d8b

Please sign in to comment.