From d4f3dcf4dff80ded472ba3061e62c6c676ffab8c Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sun, 3 Mar 2024 10:46:46 +0100 Subject: 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. --- ruby.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index d19894e4e4..d2642c96c5 100644 --- a/ruby.c +++ b/ruby.c @@ -2202,7 +2202,7 @@ process_options_global_setup(const ruby_cmdline_options_t *opt, const rb_iseq_t if ((rb_e_script = opt->e_script) != 0) { rb_str_freeze(rb_e_script); - rb_gc_register_mark_object(opt->e_script); + rb_vm_register_global_object(opt->e_script); } rb_execution_context_t *ec = GET_EC(); @@ -3070,7 +3070,7 @@ ruby_process_options(int argc, char **argv) } set_progname(external_str_new_cstr(script_name)); /* for the time being */ rb_argv0 = rb_str_new4(rb_progname); - rb_gc_register_mark_object(rb_argv0); + rb_vm_register_global_object(rb_argv0); #ifndef HAVE_SETPROCTITLE ruby_init_setproctitle(argc, argv); -- cgit v1.2.3