aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-08 01:04:22 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-08 01:04:22 -0300
commit0675210c959153ae826f3ceccb6b4fbcb2783daa (patch)
tree3fc59aae78cadaec5a161f4ee992d74cb069d3dd /railties/lib/rails
parent9bf772d936c3236267eb8f7a09dde21226125234 (diff)
downloadrails-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')
0 files changed, 0 insertions, 0 deletions