1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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 <tenderlove@ruby-lang.org>
This commit is contained in:
eileencodes 2020-09-24 14:00:51 -04:00 committed by Aaron Patterson
parent d959987891
commit 8dd9a23693
Notes: git 2020-10-02 02:11:28 +09:00

View file

@ -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