Skip to content

Commit d03c5ec

Browse files
committed
* load.c (features_index_add_single): Move loaded_features_index array values off
the ruby heap. * load.c (loaded_features_index_clear_i): Clean up off-heap array structure. * vm.c (rb_vm_mark): Remove unnecessary mark_tbl for loaded_features_index. This improves minor GC time by 15% in a large application.
1 parent ff9f9c6 commit d03c5ec

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

load.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ features_index_add_single(VALUE short_feature, VALUE offset)
203203
VALUE feature_indexes[2];
204204
feature_indexes[0] = this_feature_index;
205205
feature_indexes[1] = offset;
206-
this_feature_index = rb_ary_tmp_new(numberof(feature_indexes));
206+
this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
207+
RBASIC(this_feature_index)->flags = T_ARRAY;
207208
rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
208209
st_insert(features_index, (st_data_t)short_feature_cstr, (st_data_t)this_feature_index);
209210
}
@@ -263,6 +264,11 @@ features_index_add(VALUE feature, VALUE offset)
263264
static int
264265
loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
265266
{
267+
VALUE obj = (VALUE)val;
268+
if (!SPECIAL_CONST_P(obj)) {
269+
rb_ary_free(obj);
270+
xfree((void *)obj);
271+
}
266272
xfree((char *)key);
267273
return ST_DELETE;
268274
}

vm.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,6 @@ rb_vm_mark(void *ptr)
16121612
if (vm->loading_table) {
16131613
rb_mark_tbl(vm->loading_table);
16141614
}
1615-
if (vm->loaded_features_index) {
1616-
rb_mark_tbl(vm->loaded_features_index);
1617-
}
16181615

16191616
rb_vm_trace_mark_event_hooks(&vm->event_hooks);
16201617

0 commit comments

Comments
 (0)