I've done some more tuning for DateTime-TimeZone, and believe that I've
cut down most of the bottlenecks from DT::TZ (and it should work for
those without XS)
I based most of my profiling and performance measurements on t/02basic.t
from DateTime::TimeZone distro, and here's the summary of improvements:
- Using XS, as well as staying away from Singleton patterns
saves us about 5% memory usage, which turns out to be somewhere
around 6MB to 7MB when all zones are loaded.
- Using my already-installed version of DateTime::TimeZone (the
version from CPAN) against the optimized version, I see that
the tuned version runs t/02basic.t about 30-40seconds faster.
...And here are my random findings:
- I have to admit, while XS-fying the DateTime::TimeZone has
its merits, it's a fine line between the choice to go
with either PurePerl or XS DT::TZ, because it doesn't
improve things *that* much.
At least a straight port doesn't buy you much. If we are to
expect perfomance gains from DT::TZ side, we'd have
to rethink of the way timezone logic is handled.
However, even if we decide not to go the XS route, I strongly
suggest that the following be made:
* stay away from singletons
* incorporate my fixes to reduce date-math (see below)
- Date math is terribly slow. Most of performance improvements
from DT::TZ came from reducing the number of calls to
DateTime::add_duration(). For example,
my $diff = $dow - $dt->day_of_week;
$dt->add(days => $diff);
is definitely faster than
while ($dt->day_of_week != $dow) {
$dt->add(days => 1);
}
That also means that if we can somehow speed up DT::add_duration(),
then overall perfomance will improve significantly
- Just as a reference, here's Devel::DProf output of running
t/02basic.t against DateTime-TimeZone-XS:
Total Elapsed Time = 92.19635 Seconds
User+System Time = 42.84635 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
54.5 23.38 25.874 248526 0.0001 0.0001 Params::Validate::_validate
17.5 7.518 11.644 51285 0.0001 0.0002 DateTime::Duration::new
16.6 7.113 27.149 63321 0.0001 0.0004 DateTime::new
8.73 3.742 6.443 64095 0.0001 0.0001 DateTime::TimeZone::new
8.71 3.733 61.506 35208 0.0001 0.0017 DateTime::add_duration
7.06 3.025 23.092 34867 0.0001 0.0007 DateTime::from_object
5.15 2.207 22.768 13760 0.0002 0.0017
DateTime::TimeZone::OlsonDB::utc_d
atetime_for_time_spec
4.81 2.061 2.116 35215 0.0001 0.0001 Params::Validate::_validate_pos
4.56 1.952 2.217 64470 0.0000 0.0000
DateTime::_calc_local_components
3.98 1.707 3.700 13299 0.0001 0.0003
DateTime::TimeZone::OlsonDB::Chang
e::new
2.26 0.970 0.970 315752 0.0000 0.0000 DateTime::__ANON__
1.97 0.843 0.843 34444 0.0000 0.0000 DateTime::clone
1.90 0.813 23.050 13760 0.0001 0.0017
DateTime::TimeZone::OlsonDB::parse
_day_spec
1.74 0.747 0.572 35251 0.0000 0.0000 DateTime::set_time_zone
1.48 0.635 4.431 16075 0.0000 0.0003 DateTime::Duration::inverse
1.30 0.556 4.071 7216 0.0001 0.0006 DateTime::last_day_of_month
1.28 0.549 0.549 34866 0.0000 0.0000 DateTime::Duration::deltas
1.23 0.526 0.526 61465 0.0000 0.0000 DateTime::hms
1.16 0.497 60.143 109800 0.0000 0.0005 DateTime::_calc_utc_rd
1.12 0.482 0.608 61465 0.0000 0.0000 DateTime::ymd
1.04 0.445 0.445 35208 0.0000 0.0000 DateTime::Duration::is_zero
My changes are all available on the xs branch:
https://svn.sourceforge.net/svnroot/perl-date-time/modules/DateTime-TimeZone/branches/xs
http://svn.sourceforge.net/viewcvs.cgi/perl-date-time/modules/DateTime-TimeZone/branches/xs/
HTH.
--d