Skip to content

Commit

Permalink
discourage inlining for vm_sendish()
Browse files Browse the repository at this point in the history
reversing 9213771 only for JIT, because it made JIT slower.

$ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' --repeat-count=36 --alternate --output=all benchmark.yml
before: ruby 3.0.0dev (2020-12-19T07:38:17Z master a139318) [x86_64-linux]
after: ruby 3.0.0dev (2020-12-19T07:52:01Z master ce9faaeff5) [x86_64-linux]
last_commit=discourage inlining for vm_sendish()
before --jit: ruby 3.0.0dev (2020-12-19T07:38:17Z master a139318) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-19T07:52:01Z master ce9faaeff5) +JIT [x86_64-linux]
last_commit=discourage inlining for vm_sendish()
Calculating -------------------------------------
                                       before                 after          before --jit           after --jit
Optcarrot Lan_Master.nes    42.83365858987760     42.68912456143848     76.50136803552716     65.74704713379785 fps
                            42.87724738609940     42.89045158177300     79.72624911659534     81.26221749201044
                            43.34963955708526     42.95431841174180     80.18085951039328     82.86458983313545
                            43.56786038452823     43.57563008888242     80.45933051716041     83.09150550702445
                            43.83219269706004     43.60748924115331     80.67164125046142     83.39458202043882
                            43.99035062888973     43.62050459554573     80.93204435712701     83.56303651352751
                            44.25176047881120     44.04822899344536     81.15051082548314     83.58166141398522
                            44.41978060794512     44.06521657912991     81.35651907376140     83.80036752456826
                            44.46864790591856     44.09325484326153     81.53456531520031     83.87502933718609
                            45.54712020644544     44.70693952869038     81.97738413452767     83.95818356402224
                            45.84292299382878     44.77704345873913     82.35118338199700     83.95966387450966
                            45.89411137280815     45.41425773286726     83.01052538434648     84.12812994632024
                            45.93130099197283     46.16884439916935     83.50833510120576     84.26276094927231
                            46.13648038236674     46.66645417860622     84.88757531920830     85.41732546800056
                            46.74873798919658     46.71790568883760     84.90953097036886     85.56340808970482
                            47.11273577214855     46.74581938882115     84.93196765297411     85.57603396455576
                            47.17870777128640     46.82414166607185     84.97178445888456     86.63510466280221
                            47.19338055580042     46.83645774240446     85.43536447262163     86.74129103462393
                            47.25761413477774     46.86834469505590     85.59822430471097     86.85376073363715
                            47.53327847102834     46.90228589364909     85.76446609620548     87.26108400015282
                            47.64308771617673     47.02814519551055     85.79904863600991     87.72293541243303
                            47.80286861846863     47.44672838168050     85.88640862064263     87.86803587836525
                            47.86455937950740     47.65301489003541     85.88750199172448     88.16881051171814
                            47.90065455321760     47.73425082354376     85.94295700508701     88.71267004066843
                            47.90727961241468     47.86377917424705     85.94674546805844     88.77726627283683
                            47.93243954623904     47.88720812998766     86.51872778134982     88.78993962536994
                            47.95062952008558     47.88774830879015     86.63116771614249     88.88085054889298
                            47.95097849989396     47.89825669442417     86.77387990931732     89.72021826461126
                            48.04730571166697     47.89981045730949     86.95084011077047     89.75804193954582
                            48.08042611622322     48.03246661737583     87.87239147980547     90.05949240088842
                            48.08999523258601     48.15253490344558     88.31289344498016     90.36439442190294
                            48.25670456430854     48.26904755214532     88.33999433286937     90.54253266759406
                            48.25947200597002     48.41894159956091     88.35502296938638     90.72591894564106
                            48.30826210577268     48.43125201523194     88.58311746582939     90.77173035874087
                            48.31514124187375     48.53932287546499     88.89099681179805     91.07747476133886
                            48.44349281318267     48.58969411593706     89.34043973691581     91.08545627378257
  • Loading branch information
k0kubun committed Dec 19, 2020
1 parent 349e79b commit 8ec8f37
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions vm_insnhelper.c
Expand Up @@ -1795,9 +1795,10 @@ vm_search_method_slowpath0(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
return cc;
}

ALWAYS_INLINE(static const struct rb_callcache *vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass));

static inline const struct rb_callcache *
#ifndef MJIT_HEADER
ALWAYS_INLINE(static inline const struct rb_callcache *vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass));
#endif
static const struct rb_callcache *
vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
{
const struct rb_callcache *cc = cd->cc;
Expand Down Expand Up @@ -4427,20 +4428,46 @@ vm_invokeblock_i(struct rb_execution_context_struct *ec,
}
}

#ifdef MJIT_HEADER
static const struct rb_callcache *
vm_search_method_wrap(const struct rb_control_frame_struct *reg_cfp, struct rb_call_data *cd, VALUE recv)
{
return vm_search_method((VALUE)reg_cfp->iseq, cd, recv);
}

static const struct rb_callcache *
vm_search_invokeblock(const struct rb_control_frame_struct *reg_cfp, struct rb_call_data *cd, VALUE recv)
{
return rb_vm_empty_cc();
}

# define mexp_search_method vm_search_method_wrap
# define mexp_search_super vm_search_super_method
# define mexp_search_invokeblock vm_search_invokeblock
#else
enum method_explorer_type {
mexp_search_method,
mexp_search_invokeblock,
mexp_search_super,
};
#endif

static inline VALUE
static
#ifndef MJIT_HEADER
inline
#endif
VALUE
vm_sendish(
struct rb_execution_context_struct *ec,
struct rb_control_frame_struct *reg_cfp,
struct rb_call_data *cd,
VALUE block_handler,
enum method_explorer_type method_explorer)
{
#ifdef MJIT_HEADER
const struct rb_callcache *(*method_explorer)(const struct rb_control_frame_struct *cfp, struct rb_call_data *cd, VALUE recv)
#else
enum method_explorer_type method_explorer
#endif
) {
VALUE val;
const struct rb_callinfo *ci = cd->ci;
const struct rb_callcache *cc;
Expand All @@ -4454,6 +4481,11 @@ vm_sendish(
.ci = ci,
};

// The enum-based branch and inlining are faster in VM, but function pointers without inlining are faster in JIT.
#ifdef MJIT_HEADER
calling.cc = cc = method_explorer(GET_CFP(), cd, recv);
val = vm_cc_call(cc)(ec, GET_CFP(), &calling);
#else
switch (method_explorer) {
case mexp_search_method:
calling.cc = cc = vm_search_method_fastpath((VALUE)reg_cfp->iseq, cd, CLASS_OF(recv));
Expand All @@ -4468,6 +4500,7 @@ vm_sendish(
val = vm_invokeblock_i(ec, GET_CFP(), &calling);
break;
}
#endif

if (val != Qundef) {
return val; /* CFUNC normal return */
Expand Down

0 comments on commit 8ec8f37

Please sign in to comment.