summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-03-03 10:46:46 +0100
committerPeter Zhu <[email protected]>2024-03-06 15:33:43 -0500
commitd4f3dcf4dff80ded472ba3061e62c6c676ffab8c (patch)
tree4dd0954969e05925932b38ebd275d125f2304339 /variable.c
parent16ec54ec4177f959b6912745460fd6a96d906d82 (diff)
Refactor VM root modules
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/variable.c b/variable.c
index eaedbc2d48..b484d65d19 100644
--- a/variable.c
+++ b/variable.c
@@ -72,11 +72,11 @@ Init_var_tables(void)
autoload_mutex = rb_mutex_new();
rb_obj_hide(autoload_mutex);
- rb_gc_register_mark_object(autoload_mutex);
+ rb_vm_register_global_object(autoload_mutex);
autoload_features = rb_ident_hash_new();
rb_obj_hide(autoload_features);
- rb_gc_register_mark_object(autoload_features);
+ rb_vm_register_global_object(autoload_features);
}
static inline bool
@@ -3701,7 +3701,9 @@ rb_define_const(VALUE klass, const char *name, VALUE val)
if (!rb_is_const_id(id)) {
rb_warn("rb_define_const: invalid name '%s' for constant", name);
}
- rb_gc_register_mark_object(val);
+ if (!RB_SPECIAL_CONST_P(val)) {
+ rb_vm_register_global_object(val);
+ }
rb_const_set(klass, id, val);
}