diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-08 01:04:22 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-08 01:04:22 -0300 |
commit | 0675210c959153ae826f3ceccb6b4fbcb2783daa (patch) | |
tree | 3fc59aae78cadaec5a161f4ee992d74cb069d3dd /railties/lib/rails/info_controller.rb | |
parent | 9bf772d936c3236267eb8f7a09dde21226125234 (diff) | |
download | rails-0675210c959153ae826f3ceccb6b4fbcb2783daa.tar.gz rails-0675210c959153ae826f3ceccb6b4fbcb2783daa.tar.bz2 rails-0675210c959153ae826f3ceccb6b4fbcb2783daa.zip |
Memoized reflections accessor
Its value never change since associations are defined at class load time
so there is no need to build the hash everytime the method is called.
Before this change:
Calculating -------------------------------------
reflections 804.000 i/100ms
-------------------------------------------------
reflections 8.213k (±26.2%) i/s - 36.180k
After this change:
Calculating -------------------------------------
reflections 24.548k i/100ms
-------------------------------------------------
reflections 1.591M (±25.7%) i/s - 7.364M
Benchmark script:
require 'bundler/setup'
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
100.times do |i|
create_table "users#{i}", force: true
end
create_table :cars, force: true do |t|
100.times do |i|
t.references "users#{i}"
end
end
end
class Car < ActiveRecord::Base
100.times do |i|
belongs_to "users#{i}".to_sym
end
end
Benchmark.ips do |x|
x.report('reflections') { Car.reflections }
end
Diffstat (limited to 'railties/lib/rails/info_controller.rb')
0 files changed, 0 insertions, 0 deletions