Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find-method performance #1007

Open
epitron opened this issue Nov 13, 2013 · 0 comments
Open

find-method performance #1007

epitron opened this issue Nov 13, 2013 · 0 comments
Labels

Comments

@epitron
Copy link
Member

epitron commented Nov 13, 2013

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 methods
ObjectSpace.each_object(Module).select { |c| c.singleton_class.method_defined? :some_method_to_find }
# (stupidly fast)
@rf- rf- added the feature label Apr 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants