diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2021-11-18 16:17:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 16:17:40 -0500 |
commit | ea02b93bb95a42439631606269659dffc1981883 (patch) | |
tree | e160c058568e0de4f74911ba647a9d103a45c9ba /vm_insnhelper.c | |
parent | ab737b19197c63b84dad9944045a2fd2dc369264 (diff) |
Refactor setclassvariable (#5143)
We only need the cref when we have a cache miss so don't look it up until we
need it. This likely speeds up class variable writes in the interpreter but
also simplifies the jit code.
Before
```
Warming up --------------------------------------
write a cvar 192.280k i/100ms
Calculating -------------------------------------
write a cvar 1.915M (± 3.5%) i/s - 9.614M in 5.026694s
```
After
```
Warming up --------------------------------------
write a cvar 216.308k i/100ms
Calculating -------------------------------------
write a cvar 2.140M (± 3.1%) i/s - 10.815M in 5.058079s
```
Followup to ruby/ruby#5137
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 7323d80834..75809f7d86 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1347,8 +1347,10 @@ rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID } static inline void -vm_setclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic) +vm_setclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *reg_cfp, ID id, VALUE val, ICVARC ic) { + const rb_cref_t *cref; + if (ic->entry && ic->entry->global_cvar_state == GET_GLOBAL_CVAR_STATE()) { RB_DEBUG_COUNTER_INC(cvar_write_inline_hit); @@ -1356,7 +1358,8 @@ vm_setclassvariable(const rb_iseq_t *iseq, const rb_cref_t *cref, const rb_contr return; } - 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); rb_cvar_set(klass, id, val); |