rails/rails — pull request #11971 by jhawthorn (2013-08-22 01:27:01+00:00)
Title: Performance regression in AR::Base.respond_to?

There was a noticeable performance decrease in calling respond_to? on subclasses of `ActiveRecord::Base`. This is because the way the dynamic matchers were split into `activerecord-deprecated_finders`. The regular expression for each matcher is compiled on each respond_to?.

Benchmark.ms { 100_000.times { ActiveRecord::Base.respond_to? :foobar } }

**before:** 1934.583252
**after:** 216.642399

Performance is even more significant when the finders from `activerecord-deprecated_finders` are included.

This commit caches the patterns of `ActiveRecord::DynamicMatcher`s in a class instance variable.

It would be great if this could be merged into master as well as 4-0-stable.