Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Autosave Assocation Needlessly Uses eval()

#3429

The blog post at http://blog.pluron.com/2008/02/rails-faster-as.html talks about using String based callbacks in ActiveRecord and how they affect performance through usage of eval() and Kernel.binding. This has been patched in Rails

However I recently found that autosave_association.rb can make use of a similar patch, which I have attached.

Reported by Comron Sattari · October 26th, 2009 @ 09:56 PM

State: resolved
Milestone: 2.3.6
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran
    • Assigned user set to Eloy Duran
    • Milestone set to 2.3.6

    December 30th, 2009 @ 07:38 PM

  2. Eloy Duran
    Eloy Duran
    • State changed from new to invalid

    It's true that evaling a string should be avoided. However, the strings your patch touches are not being evaled. There's only one place in autosave_association.rb that uses eval, module_eval actually, which isn't bad because it's used to define a method, which is faster than using define_method and ok in this case. HTH

    December 31st, 2009 @ 11:01 AM

  3. Comron Sattari
    Comron Sattari

    I should have been clearer, it is the callback chain that uses the evel. In this case, after_create, after_update and validate all add these strings to the callback chain, and then evaluate_method in callbacks.rb uses eval() in the callback is a string, and send if it is a symbol. I found the problem while profiling my app.

    Please let me know if I'm misunderstanding something.

    December 31st, 2009 @ 04:15 PM

  4. Eloy Duran
    Eloy Duran
    • State changed from invalid to open

    Ah yes, you're right. Will fix! Thanks for the update :)

    December 31st, 2009 @ 04:23 PM

  5. Eloy Duran
    Eloy Duran
    • State changed from open to verified

    January 7th, 2010 @ 04:24 PM

  6. Repository
    Repository
    • State changed from verified to resolved

    (from [f866ced24ac9cdece7801f50ec79cdbe3ff5ad59]) Don't use strings for callbacks, as these will be evaled. Rather use symbols, which uses a direct method dispatch.

    Patch by Comron Sattari. [#3429 Autosave Assocation Needlessly Uses eval() state:resolved]
    http://github.com/rails/rails/commit/f866ced24ac9cdece7801f50ec79cd...

    January 7th, 2010 @ 07:15 PM

  7. Repository
    Repository

    (from [4b7a439bd17e6d9e8567758ee6a0da13447c3229]) Don't use strings for callbacks, as these will be evaled. Rather use symbols, which uses a direct method dispatch.

    Patch by Comron Sattari. [#3429 Autosave Assocation Needlessly Uses eval() state:resolved]
    http://github.com/rails/rails/commit/4b7a439bd17e6d9e8567758ee6a0da...

    January 7th, 2010 @ 07:32 PM