Hi, I''ve changed the ActiveRecord::Base#attributes method to avoid cloning of objects and increase apps performance. Here is the patch: http://dev.rubyonrails.org/ticket/11047 This sure speeds up the method avoiding Kernel#clone calls, but I don''t know if there is any special case where not cloning makes this unsafe. As koz suggested ( http://groups.google.com/group/rubyonrails-core/browse_thread/thread/faeaed67dee0ff1d/c0b0c81e9a4f6eb3) I''ve could not find cloning here being necessary and no test is broken. Any doublecheck, comment or +/-1 is welcome. Cheers, Juanjo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> Hi, > I''ve changed the ActiveRecord::Base#attributes method to avoid cloning of > objects and increase apps performance. > Here is the patch: http://dev.rubyonrails.org/ticket/11047 > This sure speeds up the method avoiding Kernel#clone calls, but I don''t > know if there is any special case where not cloning makes this unsafe. > As koz suggested ( > http://groups.google.com/group/rubyonrails-core/browse_thread/thread/faeaed67dee0ff1d/c0b0c81e9a4f6eb3 > ) I''ve could not find cloning here being necessary and no test is broken. > Any doublecheck, comment or +/-1 is welcome.The only case that breaks (that I can think of) is where you assign the attributes of one model to another, they''ll end up sharing the same instances for their attributes. For example: def test_values_copied_with_attributes_assignment new_topic = Topic.create(:title=>"Some title") other_topic = Topic.create(new_topic.attributes) assert_equal new_topic.title, other_topic.title new_topic.title.gsub!(/Some/, ''The'') assert_equal "The title", new_topic.title assert_equal "Some title", other_topic.title end With your patch that test would fail, both topics would have a title of ''The title''. I''m not particularly worried about this, but it would be best to leave it till 2.1 rather than a 2.0 point release. Anyone have any objections to this new behaviour? -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> Anyone have any objections to this new behaviour?I''ve applied the patch to edge, so if you notice any breakage shout out in this thread. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
As nobody reports any breakage, it seems natural to implement the same behaviour to attributes_before_type_cast as well. Here is the patch to avoid cloning in attributes_before_type_cast: http://dev.rubyonrails.org/ticket/11077 Cheers, Juanjo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> As nobody reports any breakage, it seems natural to implement the same > behaviour to attributes_before_type_cast as well. > > Here is the patch to avoid cloning in attributes_before_type_cast: > http://dev.rubyonrails.org/ticket/11077Agreed, applied, thanks! -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---