diff options
author | 卜部昌平 <[email protected]> | 2019-10-29 11:37:25 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2019-11-05 11:39:35 +0900 |
commit | 6ff1250739c57ce7f234a2148d3f6214da01b7e5 () | |
tree | 169447ceb51f397b202994104a514a8b1764ecd3 | |
parent | 1390d56ecfac2e430df94c4d4a60d8fa80d11166 (diff) |
rb_method_basic_definition_p with CC
Noticed that rb_method_basic_definition_p is frequently called. Its callers include vm_caller_setup_args_block(), rb_hash_default_value(), rb_num_neative_int_p(), and a lot more. It seems worth caching the method resolution part. Majority of rb_method_basic_definion_p() usages take fixed class and fixed method id combinations. Calculating ------------------------------------- ours trunk so_matrix 2.379 2.115 i/s - 1.000 times in 0.420409s 0.472879s Comparison: so_matrix ours: 2.4 i/s trunk: 2.1 i/s - 1.12x slower
Notes: Merged: https://.com/ruby/ruby/pull/2629
-rw-r--r-- | internal.h | 8 | ||||
-rw-r--r-- | vm_insnhelper.c | 16 | ||||
-rw-r--r-- | vm_method.c | 18 |
3 files changed, 37 insertions, 5 deletions
@@ -2389,6 +2389,8 @@ struct rb_call_data { }; RUBY_FUNC_EXPORTED RUBY_FUNC_NONNULL(1, VALUE rb_funcallv_with_cc(struct rb_call_data*, VALUE, ID, int, const VALUE*)); #ifdef __GNUC__ # define rb_funcallv(recv, mid, argc, argv) \ @@ -2396,6 +2398,12 @@ RUBY_FUNC_NONNULL(1, VALUE rb_funcallv_with_cc(struct rb_call_data*, VALUE, ID, static struct rb_call_data rb_funcallv_data = { { 0, }, { 0, }, }; \ rb_funcallv_with_cc(&rb_funcallv_data, recv, mid, argc, argv); \ }) #endif /* miniprelude.c, prelude.c */ @@ -1433,13 +1433,9 @@ rb_vm_search_method_slowpath(struct rb_call_data *cd, VALUE klass) } static void -vm_search_method(struct rb_call_data *cd, VALUE recv) { struct rb_call_cache *cc = &cd->cc; - VALUE klass = CLASS_OF(recv); - - VM_ASSERT(klass != Qfalse); - VM_ASSERT(RBASIC_CLASS(klass) == 0 || rb_obj_is_kind_of(klass, rb_cClass)); #if OPT_INLINE_METHOD_CACHE if (LIKELY(RB_DEBUG_COUNTER_INC_UNLESS(mc_global_state_miss, @@ -1456,6 +1452,16 @@ vm_search_method(struct rb_call_data *cd, VALUE recv) rb_vm_search_method_slowpath(cd, klass); } static inline int check_cfunc(const rb_callable_method_entry_t *me, VALUE (*func)()) { @@ -2024,6 +2024,21 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module) return module; } int rb_method_basic_definition_p(VALUE klass, ID id) { @@ -2032,6 +2047,9 @@ rb_method_basic_definition_p(VALUE klass, ID id) me = rb_method_entry(klass, id); return (me && METHOD_ENTRY_BASIC(me)) ? TRUE : FALSE; } static VALUE call_method_entry(rb_execution_context_t *ec, VALUE defined_class, VALUE obj, ID id, |