From 254477248cde5bf82c4f256dca05b13d01c9774c Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 12 Dec 2019 15:47:59 -0800 Subject: Skip optimized method check for most method IDs Previously every time a method was defined on a module, we would recursively walk all subclasses to see if the module was included in a class which the VM optimizes for (such as Integer#+). For most method definitions we can tell immediately that this won't be the case based on the method's name. To do this we just keep a hash with method IDs of optimized methods and if our new method isn't in that list we don't need to check subclasses at all. --- vm_method.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'vm_method.c') diff --git a/vm_method.c b/vm_method.c index bcf6b0b8c0..d2bd677e6a 100644 --- a/vm_method.c +++ b/vm_method.c @@ -500,7 +500,7 @@ rb_add_refined_method_entry(VALUE refined_class, ID mid) } static void -check_override_opt_method(VALUE klass, VALUE arg) +check_override_opt_method_i(VALUE klass, VALUE arg) { ID mid = (ID)arg; const rb_method_entry_t *me, *newme; @@ -512,7 +512,15 @@ check_override_opt_method(VALUE klass, VALUE arg) if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner); } } - rb_class_foreach_subclass(klass, check_override_opt_method, (VALUE)mid); + rb_class_foreach_subclass(klass, check_override_opt_method_i, (VALUE)mid); +} + +static void +check_override_opt_method(VALUE klass, VALUE mid) +{ + if (rb_vm_check_optimizable_mid(mid)) { + check_override_opt_method_i(klass, mid); + } } /* -- cgit v1.2.3