From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-03-22T22:51:52+00:00 Subject: [ruby-core:112980] [Ruby master Feature#19538] Performance warnings Issue #19538 has been updated by Eregon (Benoit Daloze). From investigating some benchmark today, I think it would be valuable to (opt-in of course) performance warn for: * uncached method lookup (i.e., the inline cache gave up, it saw too many different `obj->klass` at a call site) * singleton class creation on non-module objects (i.e., on instances). They basically cause the above, but being able to know where the singleton class is created is quite valuable and not easy to find from an uncached call site. Some amount of singleton classes on instances is fine though, the problem is if it's done repeatedly. If it's on a few global objects it's not problem, just like it's no problem on class/modules (as long as one doesn't create many classes/modules dynamically and use them at the same call site). Given the relation, I think warning for singleton class creation probably deserves a different opt-in mechanism, it's more like debugging aid for uncached method lookup (which are pretty much always bad for performance). One concern though is IIRC CRuby uses monomophic inline caches, so it would warn even for just 2 different classes seen at a call site. That seems too aggressive. TruffleRuby uses a limit of 8 which is probably too high but at least if we see more than 8 classes at a call site that's fair to call it megamorphic and not polymorphic anymore. ---------------------------------------- Feature #19538: Performance warnings https://bugs.ruby-lang.org/issues/19538#change-102509 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- Suggested by @Eregon. There are program behaviors that are supported, but that we know aren't good for performance, however it's hard for users to know about them. Now that we have warning categories, we could add a `:performance` category to allow the VM to emit warning in some situations. The category would be disabled by default, and users interested in optimizing their program could turn it on in development. ```ruby Warning[:performance] = true ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/