You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I looked into why find-method is so excruciatingly slow (it takes a minute or so on my machine). The major problem is that it's using Pry::Method.all_from_class on every single class, which does a lot of unnecessary, expensive operations.
Here's a much faster implementation:
# find classes that contain this method:classes=ObjectSpace.each_object(Module).select{ |c| c.method_defined?:some_method_to_find}# (runtime: 0.01752s)# find all instances of these classes:instances=classes.map{|c| [c,ObjectSpace.each_object(c)]}# (also really fast)
Finding class methods is the same, but with singleton_class.method_defined?:
# find classes with matching class methodsObjectSpace.each_object(Module).select{ |c| c.singleton_class.method_defined?:some_method_to_find}# (stupidly fast)
The text was updated successfully, but these errors were encountered:
I looked into why find-method is so excruciatingly slow (it takes a minute or so on my machine). The major problem is that it's using
Pry::Method.all_from_class
on every single class, which does a lot of unnecessary, expensive operations.Here's a much faster implementation:
Finding class methods is the same, but with
singleton_class.method_defined?
:The text was updated successfully, but these errors were encountered: