On 1/22/05 8:38 PM, Daisuke Maki wrote:
> I really really want to make it faster. I know that it's impossible to
> match sprintf + localtime, but wouldn't it be nice if the difference was
> an order of magnitude lower... ;)
> 
> So ... are we going to address this?

I spent a little time seeing how to make new() faster in the early days of
DateTime.   (My one good idea was added to the code back then, IIRC.)
Today, I get around the problem you're describing (using DT for date columns
in database-backed objects) by not "inflating" date columns into DateTime
objects unless I actually need to do so.

Basically, I just store the string I got from the database until/unless I
try to do something with the value.  Example:

    $e = Event->new(...);
    $e->load or ... # start and end dates are strings from the db

    print $e->start_date->strftime('%B');
                        ^
                        DateTime object created here

    $e->start_date->add(days => 1);
    $e->save or ...

At no point was a DateTime object created from the end date column.  It
round-tripped to and from the db as a string without being inflated.

Yeah, it's more annoying than just making DT magically faster, but it does
save a lot of execution time, especially if (like me) you like to put date
created and last modified date fields in most tables (which get updated by
triggers in the database and are rarely used in the perl side of things)

-John


Reply via email to