Closed arthurnn closed 10 years ago
define_attribute_methods is slow, AR.respond_to? call that method, in every call: https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods.rb#L202
define_attribute_methods
AR.respond_to?
this was introduced after https://github.com/rails/rails/commit/30efdd6e9066684dc952966ed71e23a9c7640e7e .
Make sure we dont define the methods more than one time. Almost the same way that AR does.
Benchmark using mysql+shopify Gemfile
Before: user system total real 18.800000 81.110000 99.910000 (112.324601) After: user system total real 2.310000 31.300000 33.610000 ( 40.771561)
Benchmark using sqlite3, on vanila rails4-0 stable app https://gist.github.com/arthurnn/b6b2dc053786b32bf94a
cc @jduff @camilo review @byroot
Coverage increased (+0.01%) when pulling 66448f4c2bcc4ab6e6e5a8dea7c4437661cf6522 on arthurnn:perf_regression_40 into 2bb3752ad90944324924d4054ea852c9d23be7cc on byroot:master.
Thanks!
Problem
define_attribute_methods
is slow,AR.respond_to?
call that method, in every call: https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods.rb#L202this was introduced after https://github.com/rails/rails/commit/30efdd6e9066684dc952966ed71e23a9c7640e7e .
Solution
Make sure we dont define the methods more than one time. Almost the same way that AR does.
Benchmark using mysql+shopify Gemfile
Benchmark using sqlite3, on vanila rails4-0 stable app https://gist.github.com/arthurnn/b6b2dc053786b32bf94a
cc @jduff @camilo review @byroot