CC: | 10012664 [...] ticket.noris.net |
Since determining the local timezone can be quite expensive when
_FindMatchingZoneinfoFile() comes into effect and scans a whole bunch of
files under /usr/share/zoneinfo/, I think it would be a good idea to
cache it's result on a per-process basis, e.g. by adding something like...
use Memoize qw(memoize);
memoize('_FindMatchingZoneinfoFile');
... to DateTime::TimeZone::Local::Unix, or alternatively use the patch
attached, which does not require Memoize.
I stumbled over this when debugging performance problems of a report
generator which calls DateTime->new( time_zone => 'local', [...] )
repeatedly; since we use a pre-created DateTime::TimeZone object, the
program only takes a fraction of the time to run than before.
Regards,
fany
Subject: | DateTime-TimeZone-Local-Unix.patch |
--- lib/DateTime/TimeZone/Local/Unix.pm 2009-01-21 21:47:30.000000000 +0100
+++ /usr/local/lib/perl5/site_perl/5.10.0/DateTime/TimeZone/Local/Unix.pm 2009-03-16 17:59:52.477395047 +0100
@@ -73,11 +73,18 @@
}
# for systems where /etc/localtime is a copy of a zoneinfo file
+{
+my %tz_cache;
+
sub _FindMatchingZoneinfoFile
{
my $class = shift;
my $file_to_match = shift;
+ if ( defined( my $cached_tz = $tz_cache{$class}{$file_to_match} ) ) {
+ return $cached_tz;
+ }
+
return unless -d '/usr/share/zoneinfo';
require File::Basename;
@@ -122,10 +129,12 @@
if ($@)
{
- return $real_name if ref $@ && $@->{found};
+ return $tz_cache{$class}{$file_to_match} = $real_name
+ if ref $@ && $@->{found};
die $@;
}
}
+}
sub FromEtcTimezone
{