Issue #16478 has been reported by methodmissing (Lourens Naud=E9).

----------------------------------------
Bug #16478: Fold symbol tables for tracking basic operation method redefini=
tion changes into a single ID table
https://bugs.ruby-lang.org/issues/16478

* Author: methodmissing (Lourens Naud=E9)
* Status: Open
* Priority: Normal
* Assignee: =

* Target version: =

* ruby -v: =

* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
References https://github.com/ruby/ruby/pull/2812

I stumbled onto these 2 tables (`vm_opt_method_table` and `vm_opt_mid_table=
`) while working on https://github.com/ruby/ruby/pull/2809 and experimented=
 at first with converting `vm_opt_mid_table` to an ID table for alignment w=
ith other method table concerns.

The fact that it stored a stable / constant `Qtrue` value also hinted at a =
possibility of collapsing it into one table mapping `ID` -> `basic operatio=
n` (BOP).

The `rb_method_definition_t::original_id` seems stable to me as even when a=
liased, it would not change the method definition.

I see this contract used in [dtrace](https://github.com/ruby/ruby/blob/e014=
e6bf6685f681998238ff005f6d161d43ce51/vm.c#L602) hooks, [trace instruction](=
https://github.com/ruby/ruby/blob/e014e6bf6685f681998238ff005f6d161d43ce51/=
vm.c#L601) hooks and [code coverage](https://github.com/ruby/ruby/blob/0c2d=
731ef210c9121e2a97cc5b0d7594a80389f3/ext/coverage/coverage.c#L150) as well.

For example:

```
static ID
frame_func_id(const rb_control_frame_t *cfp)
{
    const rb_callable_method_entry_t *me =3D rb_vm_frame_method_entry(cfp);

    if (me) {
	return me->def->original_id;
    }
    else {
	return 0;
    }
}

/*!
 * The original name of the current method.
 *
 * The function returns the original name of the method even if
 * an alias of the method is called.
 * The function can also return 0 if it is not in a method. This
 * case can happen in a toplevel of a source file, for example.
 *
 * \returns the ID of the name or 0
 * \sa rb_frame_callee
 * \ingroup defmethod
 */
ID
rb_frame_this_func(void)
{
    return frame_func_id(GET_EC()->cfp);
}
```

Thoughts on the viability of relying on `rb_method_definition_t::original_i=
d` as a contract for tracking method redefinition?

This change is mostly about refactoring and alignment of using an ID table =
for method ID indexed concerns. It can potentially be beneficial during for=
 example the Rails boot sequence using only 1 table (reduced inserts becaus=
e only 1 table, ID table lookups are faster) for what is usually an event w=
ith a lot of pressure on method definition. I can measure further if the di=
rection make sense.



-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>