[前][次][番号順一覧][スレッド一覧]

ruby-changes:60749

From: Takashi <ko1@a...>
Date: Sun, 12 Apr 2020 12:45:42 +0900 (JST)
Subject: [ruby-changes:60749] 5c27681813 (master): Enable fastpath on invokesuper (#3021)

https://git.ruby-lang.org/ruby.git/commit/?id=5c27681813

From 5c2768181382bf84137759efea66f3aaf212665d Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sat, 11 Apr 2020 20:45:22 -0700
Subject: Enable fastpath on invokesuper (#3021)

Fastpath has not been used for invokesuper since it has set vm_call_super_method on every invocation.
Because it seems to be blocked only by refinements, try enabling fastpath on invokesuper when cme is not for refinements.

While this patch itself should be helpful for VM performance, a part of this patch's motivation is to unblock inlining invokesuper on JIT.

$ benchmark-driver -v --rbenv 'before;after' benchmark/vm2_super.yml --repeat-count=4
before: ruby 2.8.0dev (2020-04-11T15:19:58Z master a01bda5949) [x86_64-linux]
after: ruby 2.8.0dev (2020-04-12T02:00:08Z invokesuper-fastpath c171984ee3) [x86_64-linux]
Calculating -------------------------------------
                         before       after
           vm2_super    20.031M     32.860M i/s -      6.000M times in 0.299534s 0.182593s

Comparison:
                        vm2_super
               after:  32859885.2 i/s
              before:  20031097.3 i/s - 1.64x  slower

diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 2fca2bd..21b5e93 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3032,7 +3032,7 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3032
 
       case VM_METHOD_TYPE_REFINED:
         // CC_SET_FASTPATH(cc, vm_call_refined, TRUE);
-        // should not set FASTPATH because vm_call_refined check cc->call.
+        // should not set FASTPATH since vm_call_refined assumes cc->call is vm_call_super_method on invokesuper.
         return vm_call_refined(ec, cfp, calling, cd);
     }
 
@@ -3222,7 +3222,8 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3222
             const struct rb_callcache *cc = vm_cc_new(klass, cme, vm_call_super_method);
             RB_OBJ_WRITE(reg_cfp->iseq, &cd->cc, cc);
         }
-        else {
+        else if (cached_cme->def->type == VM_METHOD_TYPE_REFINED) {
+            // vm_call_refined (search_refined_method) assumes cc->call is vm_call_super_method on invokesuper.
             vm_cc_call_set(cd->cc, vm_call_super_method);
         }
     }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]