提交 3a6dfca7 编写于 作者: A Aaron Patterson

Speed up relation merging by reducing calls to Array#-

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
上级 e68b97a4
......@@ -39,10 +39,12 @@ def initialize(relation, other)
@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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册