Closed monkbroc closed 9 years ago
Ah great catch! I thought there was always a guard check using attribute_methods_generated? before the method was called but I can't see it called anywhere in the AR/AM source.
Thanks for pulling this in! It was a lot of detective work to find out what was causing all these allocations on each request in my app :)
Thanks for the great work! How many allocations did it save? I realise this is not a generalisable number but I am just interested.
It's around 1000 string per object creation. On an index page with 20 objects it saved 20,000 string allocations out of a total of 90,000 allocations for that request. On Sep 25, 2015 12:01 AM, "Adam Meehan" notifications@github.com wrote:
Thanks for the great work! How many allocations did it save? I realise this is not a generalisable number but I am just interested.
— Reply to this email directly or view it on GitHub https://github.com/adzap/validates_timeliness/pull/128#issuecomment-143118148 .
This is a memory and performance improvement change.
The attribute methods for timeliness are generated at each object creation instead of once, at first creation like AR attribute methods. Since creating those methods uses
module_eval
it's quite slow when it's done eachModel.new
.For more details on the performance improvement, see the same change on John Carney's fork: https://github.com/johncarney/validates_timeliness/pull/6