diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2021-11-18 12:11:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 12:11:53 -0500 |
commit | ec574ab3453709490b53b5cc761ec158103fe42a (patch) | |
tree | 9fec6338decfd4dbb013ca3981df5159510a9bd4 | |
parent | d48f5082e5b5af56bc9a0986eb83bb18520f4233 (diff) |
Refactor getclassvariable (#5137)
* Refactor getclassvariable
We only need the cref when we have a cache miss so don't look it up until we
need it. This speeds up class variable reads in the interpreter but
also simplifies the jit code.
Benchmarks for master vs this branch (without yjit):
Before:
```
Warming up --------------------------------------
read a cvar 1.276M i/100ms
Calculating -------------------------------------
read a cvar 12.596M (± 1.7%) i/s - 63.781M in 5.064902s
```
After:
```
Warming up --------------------------------------
read a cvar 1.336M i/100ms
Calculating -------------------------------------
read a cvar 13.114M (± 3.6%) i/s - 65.488M in 5.000584s
```
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Clean up function signatures / remove dead code
rb_vm_getclassvariable signature has changed and we don't need
rb_vm_get_cref.
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
-rw-r--r-- | insns.def | 3 | ||||
-rw-r--r-- | vm_insnhelper.c | 11 | ||||
-rw-r--r-- | yjit_codegen.c | 15 |
3 files changed, 12 insertions, 17 deletions
@@ -236,9 +236,8 @@ getclassvariable /* "class variable access from toplevel" warning can be hooked. */ // attr bool leaf = false; /* has rb_warning() */ { - rb_cref_t * cref = vm_get_cref(GET_EP()); rb_control_frame_t *cfp = GET_CFP(); - val = vm_getclassvariable(GET_ISEQ(), cref, cfp, id, (ICVARC)ic); + val = vm_getclassvariable(GET_ISEQ(), cfp, id, (ICVARC)ic); } /* Set value of class variable id of klass as val. */ diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 06a92013bd..7323d80834 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1321,8 +1321,10 @@ update_classvariable_cache(const rb_iseq_t *iseq, VALUE klass, ID id, ICVARC ic) } static inline VALUE -vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, ICVARC ic) +vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *reg_cfp, ID id, ICVARC ic) { + const rb_cref_t *cref; + if (ic->entry && ic->entry->global_cvar_state == GET_GLOBAL_CVAR_STATE()) { VALUE v = Qundef; RB_DEBUG_COUNTER_INC(cvar_read_inline_hit); @@ -1332,15 +1334,16 @@ vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_contr } } - VALUE klass = vm_get_cvar_base(cref, cfp, 1); + cref = vm_get_cref(GET_EP()); + VALUE klass = vm_get_cvar_base(cref, reg_cfp, 1); return update_classvariable_cache(iseq, klass, id, ic); } VALUE -rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, ICVARC ic) +rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic) { - return vm_getclassvariable(iseq, cref, cfp, id, ic); + return vm_getclassvariable(iseq, cfp, id, ic); } static inline void diff --git a/yjit_codegen.c b/yjit_codegen.c index 337ccb5765..f7c9d2a010 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -4421,10 +4421,7 @@ gen_getspecial(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) } VALUE -rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, ICVARC ic); - -rb_cref_t * -rb_vm_get_cref(const VALUE *ep); +rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic); static codegen_status_t gen_getclassvariable(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb) @@ -4432,14 +4429,10 @@ gen_getclassvariable(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb) // rb_vm_getclassvariable can raise exceptions. jit_prepare_routine_call(jit, ctx, REG0); - mov(cb, C_ARG_REGS[0], member_opnd(REG_CFP, rb_control_frame_t, ep)); - call_ptr(cb, REG0, (void *)rb_vm_get_cref); - mov(cb, C_ARG_REGS[0], member_opnd(REG_CFP, rb_control_frame_t, iseq)); - mov(cb, C_ARG_REGS[1], RAX); - mov(cb, C_ARG_REGS[2], REG_CFP); - mov(cb, C_ARG_REGS[3], imm_opnd(jit_get_arg(jit, 0))); - mov(cb, C_ARG_REGS[4], imm_opnd(jit_get_arg(jit, 1))); + mov(cb, C_ARG_REGS[1], REG_CFP); + mov(cb, C_ARG_REGS[2], imm_opnd(jit_get_arg(jit, 0))); + mov(cb, C_ARG_REGS[3], imm_opnd(jit_get_arg(jit, 1))); call_ptr(cb, REG0, (void *)rb_vm_getclassvariable); |