Object#send takes 10 seconds to complete

My rails app has over 400 models and close to 2000 methods. I call
Object#send in one of them and in production it takes a 10-12 seconds
for that call to complete. In development where config.cache_classes =
false, the same call returns in less than a second. If I set
config.cache_classes = true in development, I see the same 10 second
lag. I tried using method/call and eval, but got similar response

Does send() and its ilk do some sort of lookup or scan of all the
methods to determine if the one I’m calling is defined? Should that
take 10 seconds to cover 2000 model methods?

Is there some alternative to dynamically call an object’s method that
would avoid this issue? I’d prefer to bypass any checks and just invoke
the method.

Note that the method I’m calling is not dynamically created…it exists
in the model. I just need to call it dynamically (I don’t know which
method to call until the code executes).

http://www.khelll.com/blog/ruby/ruby-dynamic-method-calling/ mentions
a few different ways to call a method dynamically, and
talks about performance. I’d try instantiating the method and then
calling it, see what happens there. Can’t really offer any inside
knowledge, though, sorry.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs