ruby-changes:44071
From: tenderlove <ko1@a...>
Date: Tue, 13 Sep 2016 00:40:14 +0900 (JST)
Subject: [ruby-changes:44071] tenderlove:r56144 (trunk): Copy the serial number from the super class to the singleton class
tenderlove 2016-09-13 00:40:09 +0900 (Tue, 13 Sep 2016) New Revision: 56144 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56144 Log: Copy the serial number from the super class to the singleton class This helps hit inline method caches more frequently. Before this commit: ``` [aaron@TC ruby (trunk)]$ time ./ruby -v benchmark/bm_vm2_poly_singleton.rb ruby 2.4.0dev (2016-09-12 trunk 56141) [x86_64-darwin15] real 0m3.679s user 0m3.632s sys 0m0.022s ``` After this commit: ``` [aaron@TC ruby (trunk)]$ time ./ruby -v benchmark/bm_vm2_poly_singleton.rb ruby 2.4.0dev (2016-09-12 trunk 56141) [x86_64-darwin15] last_commit=Copy the serial number from the super class to the singleton class real 0m2.246s user 0m2.203s sys 0m0.020s ``` [Feature #12364] [ruby-core:75425] Added files: trunk/benchmark/bm_vm2_poly_singleton.rb Modified files: trunk/ChangeLog trunk/class.c Index: benchmark/bm_vm2_poly_singleton.rb =================================================================== --- benchmark/bm_vm2_poly_singleton.rb (revision 0) +++ benchmark/bm_vm2_poly_singleton.rb (revision 56144) @@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/bm_vm2_poly_singleton.rb#L1 +class C1 + def m; 1; end +end + +o1 = C1.new +o2 = C1.new +o2.singleton_class + +i = 0 +while i<6_000_000 # benchmark loop 2 + o = (i % 2 == 0) ? o1 : o2 + o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m + i += 1 +end Index: ChangeLog =================================================================== --- ChangeLog (revision 56143) +++ ChangeLog (revision 56144) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 13 00:39:47 2016 Aaron Patterson <tenderlove@r...> + + * class.c (singleton_class_of): Copy superclass serial number to + singleton class. This improves singleton class IMC hit rates. + [Feature #12364] [ruby-core:75425] + Mon Sep 12 13:46:23 2016 Anton Davydov <mail@d...> * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::` Index: class.c =================================================================== --- class.c (revision 56143) +++ class.c (revision 56144) @@ -1591,7 +1591,9 @@ singleton_class_of(VALUE obj) https://github.com/ruby/ruby/blob/trunk/class.c#L1591 klass = RBASIC(obj)->klass; if (!(FL_TEST(klass, FL_SINGLETON) && rb_ivar_get(klass, id_attached) == obj)) { + rb_serial_t serial = RCLASS_SERIAL(klass); klass = rb_make_metaclass(obj, klass); + RCLASS_SERIAL(klass) = serial; } if (OBJ_TAINTED(obj)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/