-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements for singletons and .extend, for e.g. DCI.
DCI is some new-fangled pattern whereby you .extend functionality into objects rather than creating objects of a specific type to begin with. Regardless of the merits, there are serious performance implications from all that extending. In all Rubies, a singleton class and one or more module wrapper classes must be created. In MRI and Rubinius, all call sites must be flushed since the class hierarchy has changed in a drastic way. In JRuby, call sites that encounter singletons will not preserve caching from object to object. These are changes to ameliorate the cost of creating singleton classes and extending modules into them. * When creating a singleton, make it look like its parent for invalidation purposes * When including a module, reuse existing wrapper for the same parent/module relationship * When including a module, if child invalidation artifacts match parent, make child match wrapper The result of the changes is that unmodified singleton classes look identical to their parents, and unmodified singleton classes that have the same ancestors (modules or otherwise) look the same for invalidation purposes. This allows call sites to see calls against different singletons that reach the same methods as truly monomorphic, avoiding polymorphic call site effects. The improvement is pretty drastic, even in a small benchmark. Benchmark notes: * sclass with no calls just does class << obj; end * sclass with 10 calls does the above and calls 10 different methods on that object * extend with no calls just does obj.extend(Foo) * extend with 10 calls does the above and calls 10 different methods on that object * The numbers are highly variable due to heavy object churn; the singleton class creation is still a large, unavoidable cost * The numbers do not reflect longer-lived singleton objects that may travel far and wide BEFORE: user system total real sclass with no calls 0.156000 0.000000 0.156000 ( 0.156000) sclass with 10 calls 0.369000 0.000000 0.369000 ( 0.369000) extend with no calls 0.312000 0.000000 0.312000 ( 0.312000) extend with 10 calls 0.510000 0.000000 0.510000 ( 0.510000) user system total real sclass with no calls 0.108000 0.000000 0.108000 ( 0.109000) sclass with 10 calls 0.365000 0.000000 0.365000 ( 0.365000) extend with no calls 0.270000 0.000000 0.270000 ( 0.270000) extend with 10 calls 0.470000 0.000000 0.470000 ( 0.470000) AFTER: user system total real sclass with no calls 0.150000 0.000000 0.150000 ( 0.150000) sclass with 10 calls 0.169000 0.000000 0.169000 ( 0.169000) extend with no calls 0.209000 0.000000 0.209000 ( 0.209000) extend with 10 calls 0.227000 0.000000 0.227000 ( 0.227000) user system total real sclass with no calls 0.152000 0.000000 0.152000 ( 0.152000) sclass with 10 calls 0.132000 0.000000 0.132000 ( 0.132000) extend with no calls 0.252000 0.000000 0.252000 ( 0.252000) extend with 10 calls 0.238000 0.000000 0.238000 ( 0.238000) Conflicts: src/org/jruby/MetaClass.java src/org/jruby/RubyClass.java src/org/jruby/RubyModule.java
Showing
9 changed files
with
90 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters