From 8dd9a2369331f594de8b8541faf90c461813eb77 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Thu, 24 Sep 2020 14:00:51 -0400 Subject: Make minor improvements to super The changes here include: * Using `FL_TEST_RAW` instead of `FL_TEST` in the first check in `vm_search_super_method`. While the profile showed us spending a fair amount of time here, the subsequent benchmarks didn't show much improvement when adding this. Regardless, we know this does less work than `FL_TEST` and we know that `FL_TEST_RAW` is safe due to the previous check so it's a small but accurate optimization. * Set `mid` only once. Both `vm_ci_new_runtime` and `vm_ci_mid` were getting the `original_id` for the method entry. We can do this once and pass the variable to the 2 callers that need it. This also doesn't have a huge performance improvement but cleans up the code a bit. Benchmark: ``` | |compare-ruby|built-ruby| |:----------------|-----------:|---------:| |vm_iclass_super | 3.540M| 3.940M| | | -| 1.11x| ``` Co-authored-by: Aaron Patterson --- vm_insnhelper.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'vm_insnhelper.c') diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3d2667dfa7..ea9341429d 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3311,7 +3311,7 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c } if (BUILTIN_TYPE(current_defined_class) != T_MODULE && - !FL_TEST(current_defined_class, RMODULE_INCLUDED_INTO_REFINEMENT) && + !FL_TEST_RAW(current_defined_class, RMODULE_INCLUDED_INTO_REFINEMENT) && reg_cfp->iseq != method_entry_iseqptr(me) && !rb_obj_is_kind_of(recv, current_defined_class)) { VALUE m = RB_TYPE_P(current_defined_class, T_ICLASS) ? @@ -3332,11 +3332,14 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c " Specify all arguments explicitly."); } + ID mid = me->def->original_id; + // update iseq. really? (TODO) - cd->ci = vm_ci_new_runtime(me->def->original_id, + cd->ci = vm_ci_new_runtime(mid, vm_ci_flag(cd->ci), vm_ci_argc(cd->ci), vm_ci_kwarg(cd->ci)); + RB_OBJ_WRITTEN(reg_cfp->iseq, Qundef, cd->ci); klass = vm_search_normal_superclass(me->defined_class); @@ -3350,8 +3353,6 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c vm_search_method_fastpath((VALUE)reg_cfp->iseq, cd, klass); const rb_callable_method_entry_t *cached_cme = vm_cc_cme(cd->cc); - ID mid = vm_ci_mid(cd->ci); - // define_method can cache for different method id if (cached_cme == NULL) { // temporary CC. revisit it -- cgit v1.2.3