Skip to content

Commit 9e8a4df

Browse files
committed
Make cached_callable_method_entry not take the VM lock in the fast path
This speeds up `obj.respond_to?()` and `obj.send()`
1 parent 9fa87a6 commit 9e8a4df

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

vm_method.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,8 +1737,6 @@ complemented_callable_method_entry(VALUE klass, ID id)
17371737
static const rb_callable_method_entry_t *
17381738
cached_callable_method_entry(VALUE klass, ID mid)
17391739
{
1740-
ASSERT_vm_locking();
1741-
17421740
VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
17431741
VALUE ccs_data;
17441742

@@ -1752,12 +1750,17 @@ cached_callable_method_entry(VALUE klass, ID mid)
17521750
return ccs->cme;
17531751
}
17541752
else {
1755-
rb_managed_id_table_delete(cc_tbl, mid);
1756-
rb_vm_ccs_invalidate_and_free(ccs);
1753+
RB_VM_LOCKING() {
1754+
if (METHOD_ENTRY_INVALIDATED(ccs->cme)) {
1755+
rb_managed_id_table_delete(cc_tbl, mid);
1756+
rb_vm_ccs_invalidate_and_free(ccs);
1757+
}
1758+
}
17571759
}
17581760
}
17591761

17601762
RB_DEBUG_COUNTER_INC(ccs_not_found);
1763+
RB_GC_GUARD(cc_tbl);
17611764
return NULL;
17621765
}
17631766

@@ -1811,13 +1814,12 @@ callable_method_entry_or_negative(VALUE klass, ID mid, VALUE *defined_class_ptr)
18111814
const rb_callable_method_entry_t *cme;
18121815

18131816
VM_ASSERT_TYPE2(klass, T_CLASS, T_ICLASS);
1814-
RB_VM_LOCKING() {
1815-
cme = cached_callable_method_entry(klass, mid);
1816-
1817-
if (cme) {
1818-
if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
1819-
}
1820-
else {
1817+
cme = cached_callable_method_entry(klass, mid);
1818+
if (cme) {
1819+
if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
1820+
}
1821+
else {
1822+
RB_VM_LOCKING() {
18211823
VALUE defined_class;
18221824
rb_method_entry_t *me = search_method(klass, mid, &defined_class);
18231825
if (defined_class_ptr) *defined_class_ptr = defined_class;

0 commit comments

Comments
 (0)