From d1abf29e796a86cbac315da217f3fe7addb88106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Dec 2011 20:21:48 +0100 Subject: Remove NilClass whiners feature. Removing this feature causes boost in performance when using Ruby 1.9. Ruby 1.9 started to do implicit conversions using `to_ary` and `to_str` in some STDLIB methods (like Array#join). To do such implicit conversions, Ruby 1.9 always dispatches the method and rescues the NoMethodError exception in case one is raised. Therefore, since the whiners feature defined NilClass#method_missing, such implicit conversions for nil became much, much slower. In fact, just defining NilClass#method_missing (even without the whiners feature) already causes a massive slow down. Here is a snippet that shows such slow down: require "benchmark" Benchmark.realtime { 1_000.times { [nil,nil,nil].join } } class NilClass def method_missing(*args) raise NoMethodError end end Benchmark.realtime { 1_000.times { [nil,nil,nil].join } } --- activerecord/lib/active_record/base.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 7ba585b8e0..58d23d2f78 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2222,8 +2222,6 @@ MSG include AutosaveAssociation, NestedAttributes include Aggregations, Transactions, Reflection, Serialization, Store - NilClass.add_whiner(self) if NilClass.respond_to?(:add_whiner) - # Returns the value of the attribute identified by attr_name after it has been typecast (for example, # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). # (Alias for the protected read_attribute method). -- cgit v1.2.3