-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extremely inefficient instantiating a distant local date #12
Comments
From autarch@urth.org (@autarch) on 2009-07-08 02:08:38: On Tue, 7 Jul 2009, Michael G Schwern via RT wrote:
It's generating all the time zone changes from X years out (by default, Note that this only affects zones with DST rules in effect.
The problem being that there's nothing to search until it's generated. While I'm sure this could be made faster, I'm not sure it's worth too much Just use UTC. -dave /============================================================ |
From mschwern@cpan.org (@schwern) on 2009-07-08 03:02:01: On Tue Jul 07 22:08:38 2009, autarch@urth.org wrote:
Are you saying it regenerates the database at run time every time? How
What the hell kind of answer is that?! I'll take "yeah, that sucks but While I agree worrying about the niggling details of historical time Another simple optimization would be to cache what the latest Olsen Somewhat apropos, for dates far in the past, before time zones, I've |
From autarch@urth.org (@autarch) on 2009-07-08 03:37:39: On Tue, 7 Jul 2009, Michael G Schwern via RT wrote:
Storing the changes in memory uses up a fair bit of memory. Generating 1000+ years worth would make loading each time zone take much
It's the right answer. Using Olson time zones with far future dates just
Yes, that's what the offset reflects. However, the DST changes reflect If you just want an offset, use a static offset like '-0500'. That will be
That doesn't make any sense. The last Olson entry is purely arbitrary Or do you mean the offset without DST? Then someone else will complain For people who need to calculate far future dates, there are other If you want to take a stab at optimizing the changes generation, that's
A DT::TZ::LatLong would be very cool. Actually, the Olson database approximates this, since pre-modern times it -dave /============================================================ |
From schwern@pobox.com on 2009-07-08 09:57:18: autarch@urth.org via RT wrote:
Generating 1000+ years of what? The Olsen database doesn't go forward that The C code figured this out 20 years ago!
You're absolutely correct, it sucks and its broken. However, you maintain a
I, in fact, don't want an offset at all. I just want a DateTime object
Ok, maybe I'm missing something here. If I hand you something like "July 9th, Why would the algorithm be any different for 3009? What's all this extra
Look, all I know is every other datetime library that goes past 2038 doesn't
That sounds like it. The past has a vote, but not a veto. |
From mschwern@cpan.org (@schwern) on 2009-07-08 19:57:25: I've dug into the DateTime::TimeZone code and now I understand why we're Since they're linear, and since the only way to search through them is I understand the approach, but there's got to be a better way to do it |
From autarch@urth.org (@autarch) on 2009-07-08 21:21:33: On Wed, 8 Jul 2009, Michael G Schwern via RT wrote:
They're indexed by UTC days.
Probably the quickest, most efficient way would be to have the time zone -dave /============================================================ |
From schwern@pobox.com on 2009-07-08 23:43:42: autarch@urth.org via RT wrote:
Presumably this is the number of UTC days since some epoch? What's the epoch?
Ah HA! That's the mysterious "rd". Alligator sandwich, and make it snappy! |
From autarch@urth.org (@autarch) on 2009-07-09 01:32:56: Can we take this conversation to the datetime@perl.org list? /============================================================ |
Migrated from rt.cpan.org #47671 (status was 'open')
Requestors:
From mschwern@cpan.org (@schwern) on 2009-07-08 02:01:30:
$ time perl -wle 'use DateTime; print DateTime->new( year => 3058,
time_zone => "local" )'
3058-01-01T00:00:00
real 0m9.558s
user 0m8.619s
sys 0m0.165s
This occurs whether time_zone is "local" or set to a zone like
"America/Chicago".
Profiling reveals that this makes tens of thousands of method calls.
The big hog is 10000 calls to DateTime::set_time_zone which is being
called by add_duration() which all traces back to
DateTime::TimeZone::_generate_spans_until_match looping over OlsenDB
calls 2000+ times.
This all traces back to DateTime->offset called by
DateTime::_handle_offset_modifier and DateTime::_calc_local_rd
Its possible one could hold off doing whatever it is that calc_local_rd
does, considering that information is not necessary just to instantiate
an object, but the root problem is _generate_spans_until_match's
algorithm. I'm not sure what its purpose is, but it appears to be
iterative by year resulting in Y iterations where Y is the year being
search for (minus some arbitrary lower limit).
If the whole purpose is to determine the time zone offset, this
algorithm is much more efficiently done as a binary search. Even if we
assume a 64 bit year it will take at most 64 iterations to zero in on
the right year. And so on for the month, day, hour, minute and second.
If its just searching the Olsen DB for applicable zone changes I don't
pretend to understand how that works but there's got to be a better way
to do it. C libraries can do it in milliseconds and Perl is just not
that slow. Perhaps with some sort of... database?
The text was updated successfully, but these errors were encountered: