Browse files

Make sure require_tzinfo only calls Kernel#require if TZInfo isn't al…

…ready present.

This wasn't a problem when require_tzinfo was only called from TimeZone#initialize, but now it's being called for every lookup to TimeZone.[] (via lazy_zones_map)

TimeZone lookup can occur when unmarshalling TimeWithZone objects, which is where I first saw the big slowdown (500ms for each Rails action that loaded from Rails.cache)
  • Loading branch information...
1 parent df21e3d commit d6d474032a27c6ea86e97e7011b1e66de4b7c652 @toolmantim toolmantim committed Sep 7, 2011
Showing with 3 additions and 1 deletion.
  1. +2 −0 activesupport/CHANGELOG
  2. +1 −1 activesupport/lib/active_support/values/time_zone.rb
@@ -1,5 +1,7 @@
*Rails 3.1.1 (unreleased)*
+* Fixed performance issue where TimeZone lookups would require tzinfo each time [Tim Lucas]
* ActiveSupport::OrderedHash is now marked as extractable when using Array#extract_options! [Prem Sichanugrist]
*Rails 3.1.0 (August 30, 2011)*
@@ -373,7 +373,7 @@ def us_zones
def require_tzinfo
- require 'tzinfo'
+ require 'tzinfo' unless defined?(::TZInfo)
rescue LoadError
$stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"

0 comments on commit d6d4740

Please sign in to comment.