Closed Bug 696537 Opened 15 years ago Closed 15 years ago

Load DateTime only when datetime_from() is called

Categories

(Bugzilla :: Bugzilla-General, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Bugzilla 4.4

People

(Reporter: LpSolit, Assigned: LpSolit)

Details

(Keywords: perf)

Attachments

(1 file)

On my machine, Bugzilla wastes 110ms loading DateTime when Bugzilla::Util is loaded despite DateTime is only used in datetime_from(), i.e. mostly when viewing bugs and buglists. And this is by far the external module which consumes the most time, 15-20x more time than any other external module loaded by Bugzilla::Util. So we should only load it when datetime_from() is called. An alternative could be to write use autouse 'DateTime'; so that it's only loaded if datetime_from() is called. This gives similar results to moving DateTime into the subroutine. autouse exists since Perl 5.4, see http://perldoc.perl.org/autouse.html. mkanat seems to have a preference for |require DateTime| though.
Attached patch patch, v1 — — Splinter Review
DateTime::TimeZone is no longer needed as some of the code has been refactored into Bugzilla->local_timezone (and I forgot to remove it when refactoring it).
Assignee: general → LpSolit
Status: NEW → ASSIGNED
Attachment #568836 - Flags: review?(mkanat)
Comment on attachment 568836 [details] [diff] [review] patch, v1 Review of attachment 568836 [details] [diff] [review]: ----------------------------------------------------------------- Hmm. So, I'm curious--does this change the loading time of an actual page? I have a suspicion that the large time-user is DateTime::TimeZone, actually, and that's being used all over the place. Also, I see a few other "use DateTime" calls in Bugzilla; I wonder if we really need all of them, or if we should be using datetime_from for some of those places.
(In reply to Max Kanat-Alexander from comment #2) > Hmm. So, I'm curious--does this change the loading time of an actual page? Yes, the win on my machine is ~100ms for pages which do not call datetime_from(), and the time is the same otherwise. DateTime::TimeZone is actually fast, so this is not a problem. I will look if we can remove some other |use DateTime| and/or |use DateTime::TimeZone|.
Comment on attachment 568836 [details] [diff] [review] patch, v1 Review of attachment 568836 [details] [diff] [review]: ----------------------------------------------------------------- ::: Bugzilla/Util.pm @@ +478,4 @@ > delete $args{$arg} if !defined $args{$arg}; > } > > + require DateTime; Add a comment above this explaining why you're doing a require instead of a use, and we're good to go.
Attachment #568836 - Flags: review?(mkanat) → review+
Flags: approval+
Target Milestone: --- → Bugzilla 5.0
Committing to: bzr+ssh://lpsolit%40gmail.com@bzr.mozilla.org/bugzilla/trunk/ modified mod_perl.pl modified Bugzilla/Util.pm Committed revision 8003.
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: