From 3a6dfca7f5f5bd45cea2f6ac348178e72423e1d5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 12 Oct 2012 14:34:04 -0700 Subject: Speed up relation merging by reducing calls to Array#- MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit before: Calculating ------------------------------------- ar 83 i/100ms ------------------------------------------------- ar 832.1 (±4.0%) i/s - 4233 in 5.096611s after: Calculating ------------------------------------- ar 87 i/100ms ------------------------------------------------- ar 839.0 (±9.3%) i/s - 4176 in 5.032782s Benchmark: require 'config/environment' require 'benchmark/ips' GC.disable unless User.find_by_login('tater') u = User.new u.login = 'tater' u.save! end def active_record user = User.find_by_login('tater') starred = user.starred_items.count end active_record Benchmark.ips do |x| x.report("ar") { active_record } end --- activerecord/lib/active_record/relation/merger.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index e5b50673da..951eabe427 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -39,10 +39,12 @@ module ActiveRecord @values = other.values end + NORMAL_VALUES = Relation::SINGLE_VALUE_METHODS + + Relation::MULTI_VALUE_METHODS - + [:where, :order, :bind, :reverse_order, :lock, :create_with, :reordering, :from] # :nodoc: + def normal_values - Relation::SINGLE_VALUE_METHODS + - Relation::MULTI_VALUE_METHODS - - [:where, :order, :bind, :reverse_order, :lock, :create_with, :reordering, :from] + NORMAL_VALUES end def merge -- cgit v1.2.3