diff options
author | Jemma Issroff <jemmaissroff@gmail.com> | 2022-11-22 15:28:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 15:28:14 -0500 |
commit | 9c5e3671ebd9c07c178ca5dac08ad15ad1eae411 (patch) | |
tree | 06f4f0560176011f14832d82f9e141ead7cac3f2 /vm_insnhelper.c | |
parent | 20b9d7b9fde83c98046eacdfcb40e8cb6607963e (diff) |
Increment max_iv_count on class based on number of set_iv in initialize (#6788)
We can loosely predict the number of ivar sets on a class based on the
number of iv set instructions in the initialize method. This should give
us a more accurate estimate to use for initial size pool allocation,
which should in turn give us more cache hits.
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 76bdbb86de..073c515d3c 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4946,6 +4946,11 @@ vm_define_method(const rb_execution_context_t *ec, VALUE obj, ID id, VALUE iseqv } rb_add_method_iseq(klass, id, (const rb_iseq_t *)iseqval, cref, visi); + // Set max_iv_count on klasses based on number of ivar sets that are in the initialize method + if (id == rb_intern("initialize") && klass != rb_cObject && RB_TYPE_P(klass, T_CLASS) && (rb_get_alloc_func(klass) == rb_class_allocate_instance)) { + + RCLASS_EXT(klass)->max_iv_count = rb_estimate_iv_count(klass, (const rb_iseq_t *)iseqval); + } if (!is_singleton && vm_scope_module_func_check(ec)) { klass = rb_singleton_class(klass); |