summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorJohn Hawthorn <[email protected]>2024-02-11 21:43:38 -0800
committerJohn Hawthorn <[email protected]>2024-02-20 18:55:00 -0800
commit1c97abaabae6844c861705fd07f532292dcffa74 (patch)
treea1d5dbac7eab32f6ffc168f1e556dfac085bc89a /vm.c
parent2a6917b463fa4065f26aea44802e2e24cc494e4c (diff)
De-dup identical callinfo objects
Previously every call to vm_ci_new (when the CI was not packable) would result in a different callinfo being returned this meant that every kwarg callsite had its own CI. When calling, different CIs result in different CCs. These CIs and CCs both end up persisted on the T_CLASS inside cc_tbl. So in an eval loop this resulted in a memory leak of both types of object. This also likely resulted in extra memory used, and extra time searching, in non-eval cases. For simplicity in this commit I always allocate a CI object inside rb_vm_ci_lookup, but ideally we would lazily allocate it only when needed. I hope to do that as a follow up in the future.
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 4f0e684bae..9c112d039b 100644
--- a/vm.c
+++ b/vm.c
@@ -2873,6 +2873,7 @@ rb_vm_update_references(void *ptr)
if (ptr) {
rb_vm_t *vm = ptr;
+ rb_gc_update_tbl_refs(vm->ci_table);
rb_gc_update_tbl_refs(vm->frozen_strings);
vm->mark_object_ary = rb_gc_location(vm->mark_object_ary);
vm->load_path = rb_gc_location(vm->load_path);
@@ -3119,6 +3120,10 @@ ruby_vm_destruct(rb_vm_t *vm)
st_free_table(vm->loading_table);
vm->loading_table = 0;
}
+ if (vm->ci_table) {
+ st_free_table(vm->ci_table);
+ vm->ci_table = NULL;
+ }
if (vm->frozen_strings) {
st_free_table(vm->frozen_strings);
vm->frozen_strings = 0;
@@ -3209,6 +3214,7 @@ vm_memsize(const void *ptr)
rb_vm_memsize_workqueue(&vm->workqueue) +
rb_st_memsize(vm->defined_module_hash) +
vm_memsize_at_exit_list(vm->at_exit) +
+ rb_st_memsize(vm->ci_table) +
rb_st_memsize(vm->frozen_strings) +
vm_memsize_builtin_function_table(vm->builtin_function_table) +
rb_id_table_memsize(vm->negative_cme_table) +
@@ -4303,6 +4309,7 @@ Init_vm_objects(void)
/* initialize mark object array, hash */
vm->mark_object_ary = rb_ary_hidden_new(128);
vm->loading_table = st_init_strtable();
+ vm->ci_table = st_init_table(&vm_ci_hashtype);
vm->frozen_strings = st_init_table_with_size(&rb_fstring_hash_type, 10000);
}